假设您想在用户完成后做某事。你做什么工作?
它没有代表。关闭当前视图控制器后该怎么办?
在 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];
}
}