2

ユーザーが共有を投稿またはキャンセルしたかどうかに応じて、キャンセルまたは成功したアラートを表示するという単純なタスクを実行しようとしています。以下に概説するように、iOS 6 共有機能を使用しています。

NSArray *activityItems = @[textToShare, urlToShare];
UIActivityViewController *activityVC = [[UIActivityViewController 
alloc]initWithActivityItems:activityItems applicationActivities:nil];

[activityVC setExcludedActivityTypes:[NSArray arrayWithObjects:
                                      UIActivityTypeCopyToPasteboard,
                                      UIActivityTypeAssignToContact,
                                      UIActivityTypePostToWeibo,
                                      UIActivityTypePrint,
                                      UIActivityTypeSaveToCameraRoll,
                                      nil]];

[self presentViewController:activityVC animated:TRUE completion:nil];

以下に概説するように、Facebook の SLServiceType を使用してキャンセル/成功アラートを機能させることができますが、上記の単純な activityVC バージョンではこれを機能させることができないようです。どんな助けでも大歓迎です!

- (IBAction)facebookPost:(id)sender {

    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

        SLComposeViewController *mySLComposerSheet = [SLComposeViewController 
        composeViewControllerForServiceType:SLServiceTypeFacebook];

        [mySLComposerSheet setInitialText:@"Sample Share"];

        [mySLComposerSheet addImage:[UIImage imageNamed:@"myImage.png"]];

        [mySLComposerSheet addURL:[NSURL URLWithString:@"http://www.website.com"]];

        [mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {

            switch (result) {
                case 0:
                {
                SLComposeViewControllerResultCancelled:
                    NSLog(@"Post Canceled");

                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Cancelled"
                    message:@"You must be connected to the internet to use this app."
                    delegate:nil
                    cancelButtonTitle:@"OK"
                    otherButtonTitles:nil];
                    [alert show];

                    break;
                }
                case 1:
                {

                SLComposeViewControllerResultDone:
                    NSLog(@"Post Sucessful");

                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Successful"
                    message:@"You must be connected to the internet to use this app."
                    delegate:nil
                    cancelButtonTitle:@"OK"
                    otherButtonTitles:nil];
                    [alert show];

                    break;
                }

                default:
                    break;

            }      

        }]; 

        [self presentViewController:mySLComposerSheet animated:YES completion:nil];
    }
}
4

0 に答える 0