Sharing via Uiactivityviewcontroller

Asked

Viewed 59 times

1

Could someone help me solve the problem called: "Launchservices: invalidationHandler called" whenever I press a certain BarButtonItem, follows below the excerpt of the code 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)
}

1 answer

0

When building a UIActivityViewController you need to enter a NOT-null list as the first argument activityItems. 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 the presentViewController:

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

    presentationController.sourceView = sender; //Se for botão, alternativa: self.view
}
  • Ola Ricardo, the error still persists, when executing Action Barbuttonitem, keeps presenting the error message: Launchservices: invalidationHandler called

  • This is an Apple bug: https://devforums.apple.com/message/1049415#1049415

Browser other questions tagged

You are not signed in. Login or sign up in order to post.