1

I am trying to present activity view controller. it used to work fine on Iphones, but apparently, one has to use popover on iPad or else the app crashes. I have done the following:

    var sharingItems = [AnyObject]()

    if let text = sharingText {
        sharingItems.append(text)
    }
    if let image = sharingImage {
        sharingItems.append(image)
    }
    if let url = sharingURL {
        sharingItems.append(url)
    }

    let activityViewController = UIActivityViewController(activityItems: sharingItems, applicationActivities: nil)
    activityViewController.excludedActivityTypes = [UIActivityTypeCopyToPasteboard,UIActivityTypeAirDrop,UIActivityTypeAddToReadingList,UIActivityTypeAssignToContact,UIActivityTypePostToTencentWeibo,UIActivityTypePostToVimeo,UIActivityTypePrint,UIActivityTypeSaveToCameraRoll,UIActivityTypePostToWeibo]
    var currentViewController:UIViewController=UIApplication.sharedApplication().keyWindow!.rootViewController!


    if respondsToSelector("popoverPresentationController") {
        let popup = UIPopoverController(contentViewController: activityViewController)
        popup.presentPopoverFromRect(CGRectMake(self.frame.size.width/2, self.frame.size.height/4, 0, 0), inView: self.view!, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true)
    }else{
        currentViewController.presentViewController(activityViewController, animated: true, completion: nil)
    }

But the app still crashes. I have read something about anchoring it, but did not succeed in implementing it. Anyone knows how to solve this?

EDIT:

This is the error I am getting:

(<_UIAlertControllerActionSheetRegularPresentationController: 0x7cf42f80>) should have a non-nil sourceView or barButtonItem set before the presentation occurs.'

TruniTr
  • 366
  • 3
  • 14
  • Can you post the error from the console? Or set an exception breakpoint to see what line it crashes at? Also, why are you getting `currentViewController`? Why can't you use `self`? – Mark Jun 22 '15 at 11:57
  • I edited my question so you know the exception. And for the second part of your question - no reason. Have been trying to find something that works and hence experimented with what I have found. – TruniTr Jun 22 '15 at 12:04
  • Possible duplicate of [UIActivityViewController on iPad](https://stackoverflow.com/questions/32889680/uiactivityviewcontroller-on-ipad) – BDL Jun 25 '18 at 09:25

0 Answers0