WhatsApp with UIActivityViewController for sharing image not using UIDocumentInteractionController

iOS_Raj picture iOS_Raj · Apr 29, 2014 · Viewed 10.6k times · Source

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.

Answer

Mr. Bean picture Mr. Bean · Jan 29, 2016

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 })