On iOS8 I'm using a UIActivityViewController to share a UIImage to Facebook/Twitter etc. It seemed to be working fine, but today it suddenly started crashing when running the code on my iPad. However, it still works as expected in the simulator.
My code:
UIActivityViewController *controller =
[[UIActivityViewController alloc]
initWithActivityItems:@[text, url, myImage]
applicationActivities:nil];
[self presentViewController:controller animated:YES completion:nil];
Upon crashing, Xcode spits out:
Discovered extensions: {( {id = com.apple.share.Facebook.post}, {id = com.apple.share.Twitter.post}, {id = com.apple.share.TencentWeibo.post}, {id = com.apple.share.SinaWeibo.post} )} for attributes: { NSExtensionActivationRule = { extensionItems = ( { attachments = ( { registeredTypeIdentifiers = ( "public.image" ); }, { registeredTypeIdentifiers = ( "public.plain-text" ); }, { registeredTypeIdentifiers = ( "public.url" ); } ); } ); }; NSExtensionPointName = ( "com.apple.share-services", "com.apple.ui-services", "com.apple.services" ); } 2014-08-07 21:38:59.208 collageTest[279:11021] LaunchServices: invalidationHandler called 2014-08-07 21:38:59.212 collageTest[279:11016] Discovered extensions: {( {id = com.apple.share.Flickr.post}, {id = com.apple.mobileslideshow.StreamShareService}, {id = com.apple.share.Twitter.post}, {id = com.apple.share.Facebook.post}, {id = com.apple.share.Vimeo.post}, {id = com.apple.share.SinaWeibo.post}, {id = com.apple.share.TencentWeibo.post} )} for attributes: { NSExtensionPointName = "com.apple.share-services"; } 2014-08-07 21:38:59.216 collageTest[279:11021] LaunchServices: invalidationHandler called
Looking at the docs, I needed to define a source view for the popover controller
UIActivityViewController *controller =
[[UIActivityViewController alloc]
initWithActivityItems:@[text,url,myImage]
applicationActivities:nil];
[self presentViewController:controller animated:YES completion:nil];
UIPopoverPresentationController *presentationController =
[controller popoverPresentationController];
presentationController.sourceView = self.view;