我已经在我的应用程序(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 被执行)。
如何防止这种情况?