简体   繁体   中英

WhatsApp with UIActivityViewController for sharing image not using UIDocumentInteractionController

How to set up WhatsApp with UIActivityViewController for sharing image, not using UIDocumentInteractionController . Please let me know if there is another way. Thanks in advance.

This is the code to share text and url from activity controller

NSString *URLString=@"http://video.app.com/video.php?";

NSURL *VideoURL=[NSURL URLWithString:URLString];

NSMutableArray *activityItems= [NSMutableArray arrayWithObjects:VideoURL, @"Hey, check out this video I've shared with you, it's awesome!", nil];

self.activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
self.activityViewController.excludedActivityTypes = @[UIActivityTypePostToWeibo,UIActivityTypePrint,
                                                      UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact,
                                                      UIActivityTypeSaveToCameraRoll,UIActivityTypeAddToReadingList,
                                                      UIActivityTypePostToFlickr,UIActivityTypePostToVimeo,
                                                      UIActivityTypePostToTencentWeibo,UIActivityTypeAirDrop];

[self presentViewController:self.activityViewController animated:YES completion:nil];

For Swift 3.0

let objectsToShare = ["\(Title) \n \(Description)"]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
activityVC.setValue("App Name", forKey: "subject")

let excludeActivities = [UIActivityType.airDrop, UIActivityType.print, UIActivityType.assignToContact, UIActivityType.saveToCameraRoll, UIActivityType.addToReadingList, UIActivityType.postToFlickr, UIActivityType.postToVimeo, UIActivityType.postToFacebook, UIActivityType.message, UIActivityType.postToWeibo]
activityVC.excludedActivityTypes = excludeActivities

self.present(activityVC, animated: true, completion: { _ in })

Try the URL scheme approach described here on the official WhatsApp site:

https://www.whatsapp.com/faq/iphone/23559013

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM