アプリ (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];
}
次の状況をテストしています。
- インターネットが利用可能で、ユーザーがテキストを入力し、投稿を押す
- インターネットが利用可能で、ユーザーがテキストを入力してキャンセルを押した
- インターネットが利用できず、ユーザーがテキストを入力して投稿を押した。
最初の 2 つは正常に動作します。3番目の状況では、予想どおり、アラートが表示されます
"Cannot Post to Facebook" - The post cannot be sent because connection to Facebook failed.
しかし、表示されたアラート ビューで [再試行] または [キャンセル] ボタンを押すと、「投稿済み」アラートが表示されます (完了ハンドラー タイプ SLComposeViewControllerResultDone が実行されます)。
これを防ぐ方法は?