目前,我的应用程序可以选择使用 SLComposeViewController 在 Facebook 和 Twitter 上分享。
SLComposeViewController *fbComposeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbComposeViewController setInitialText:text_short];
[fbComposeViewController addURL:url];
[self.navigationController presentViewController:fbComposeViewController
animated:YES
completion:^{
NSLog(@"fb activity completed");
}];
我可以分享到其他网站,例如 Gmail、Whatsapp、Message 和 Mail,使用
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:@[text, url]
applicationActivities:nil];
controller.excludedActivityTypes = @[UIActivityTypePostToWeibo,
UIActivityTypePrint,
UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo,
UIActivityTypePostToTencentWeibo,
UIActivityTypeAirDrop,
UIActivityTypePostToFacebook,
UIActivityTypePostToTwitter
];
[self presentViewController:controller animated:YES completion:nil];
但是,这会启动一个共享表,用户必须在其中选择他必须启动的应用程序。有没有办法通过指定活动名称直接启动共享对话框?例如,Uber 中的 Whatsapp、电子邮件和文本邀请。