Sharing via UIActivityViewController

1

Could anyone help me solve the problem called: " LaunchServices: invalidationHandler called" displays whenever I press a certain BarButtonItem , below is the code snippet in SWIFT.

@IBAction func btShared(sender: UIBarButtonItem) {

   let myActivity: UIActivityViewController =    
   UIActivityViewController(activityItems: [url], applicationActivities: nil)

   myActivity.excludedActivityTypes = [UIActivityTypeCopyToPasteboard]

   self.presentViewController(myActivity, animated: true, completion: nil)
}
    
asked by anonymous 03.12.2014 / 02:45

1 answer

0

When constructing a UIActivityViewController you have to indicate a non-null list as the first activityItems argument. It must contain at least one item.

Example:

let someText:String = textView.text
let google:NSURL = NSURL(string:"http://google.com/")

let activityViewController = UIActivityViewController(
        activityItems: [someText, google],
        applicationActivities: nil)

self.navigationController.presentViewController(activityViewController, animated: true, completion: nil)

Edited: to avoid error (Objective-C)

Add after presentViewController :

if ([activityVC respondsToSelector:@selector(popoverPresentationController)])
{
    // iOS 8+
    UIPopoverPresentationController *presentationController = [activityVC popoverPresentationController];

    presentationController.sourceView = sender; //Se for botão, alternativa: self.view
}
    
03.12.2014 / 12:07