目前我的应用程序可以选择使用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,消息和邮件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,电子邮件和文本邀请。
答案 0 :(得分:3)
例如,如果您要分享whatsapp
// this is your share content message
NSString * msg = @"ApplNSString YOUR MSG";
NSString * urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=%@",msg];
NSURL * whatsappURL = [NSURL URLWithString:[urlWhats stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
// this is identify if whatsapp is already install your device , if yes it open the whatsapp and share the content
if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
[[UIApplication sharedApplication] openURL: whatsappURL];
} else {
// it shows the alert for no application found
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"WhatsApp not installed." message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}