【发布时间】:2015-11-18 11:34:42
【问题描述】:
我想将图片、网址和文本分享到 facebook,但无法在 iOS9 上使用。这是我的代码。
-(IBAction)shareOnFacebook:(id)sender{
UIButton *btn = (UIButton *)sender;
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:SHARING_QUOTE_D(self.dish.name, self.dish.restaurant.name)];
[controller addURL:[NSURL URLWithString:SHARING_URL]];
[controller addImage:self.dishImageView.image];
[self presentViewController:controller animated:YES completion:Nil];
if ([controller respondsToSelector:@selector(popoverPresentationController)])
{
UIPopoverPresentationController *presentationController = [controller popoverPresentationController];
presentationController.sourceView = btn; // if button or change to self.view.
}
}else{
[[[UIAlertView alloc] initWithTitle:@"Error Message" message:@"Please log into your Facebook account to post" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil] show];
}
}
【问题讨论】:
-
添加一个完成处理程序......这对我有用[facebook setCompletionHandler:^(SLComposeViewControllerResult result) { switch (result) { case SLComposeViewControllerResultCancelled: NSLog(@"Post Canceled");休息; case SLComposeViewControllerResultDone: NSLog(@"Post Sucessful");休息;默认值:中断; } }];
-
添加了它。但仍然无法正常工作。
标签: ios objective-c facebook ios9 slcomposeviewcontroller