我已经在我的应用程序(iOS6)中实现了Facebook分享功能,代码如下。
//完成处理程序
我正在测试以下情况:
//完成处理程序
SLComposeViewControllerCompletionHandler __block completionHandler = ^(SLComposeViewControllerResult result) {
UIAlertView *alert = nil;
switch(result) {
case SLComposeViewControllerResultCancelled: {
alert = [UIAlertView alloc]initWithTitle:@"Cancelled" message:@"Your message wasn't shared" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
break;
case SLComposeViewControllerResultDone: {
alert = [UIAlertView alloc]initWithTitle:@"Posted" message:@"Your message was posted successfully" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
break;
}
}
// 发布到 Facebook
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *fbVC = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
fbVC.completionHandler = completionHandler;
[self presentViewController:fbVC animated:YES completion:nil];
}
我正在测试以下情况:
- 互联网可用且用户输入了文本并点击了发布按钮
- 互联网可用且用户输入了文本并点击了取消按钮
- 互联网不可用且用户输入了文本并点击了发布按钮。
"Cannot Post to Facebook" - The post cannot be sent because connection to Facebook failed.
但是,当我在弹出的警告视图中按下"重试"或"取消"按钮后,我会得到一个"已发布"的警告(执行了完成处理程序类型SLComposeViewControllerResultDone)。
如何防止这种情况发生?