Proper way to present activity view controller n iPad

685 views Asked by At

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.'

0

There are 0 answers