为什么SLComposeViewController没有委托?

时间:2013-08-28 10:17:22

标签: ios slcomposeviewcontroller

假设您希望在用户完成后执行某些操作。你做什么的?

它没有委托。一旦当前视图控制器被解除,该怎么办?

1 个答案:

答案 0 :(得分:3)

在Apple文档中,您会发现SLComposeViewController具有完成处理程序属性而不是委托。您只需要使用setCompletionHandler方法设置该属性。然后使用常量SLComposeViewControllerResult来恢复帖子是发布还是取消,并相应地采取措施。

-(void) shareToFacebook {
//1. Set link and image
NSString *appLink = @"https://itunes.apple.com/app/id989793966";
UIImage *twitterImage = [UIImage imageNamed:@"TF_400x400.png"];

//2. Check if we can share
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

    //3. Compose the share view controller
    SLComposeViewController *FBViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

    [FBViewController addURL:[NSURL URLWithString:appLink]];

    [FBViewController addImage:twitterImage];

    //4 Set completion handler and define actions to take
    [FBViewController setCompletionHandler:^(SLComposeViewControllerResult result)
     {
         if (result == SLComposeViewControllerResultCancelled) {

             [self addEmptyScreenButtonTargets];

         } else if (result == SLComposeViewControllerResultDone) {

             //Unlock words; show thank you screen
             [NewCardManager unlockWordsForPackage:4];

             [self openFBThankYouScreen];  
         }
     }];

    //5. Call to modally present the share controller
    [self presentViewController:FBViewController animated:YES completion:nil];
}

}

相关问题