简体   繁体   中英

Swift: UIActivityViewController is empty

I trying to create UIActivityViewController. But it appears empty, only with "Copy". No Twitter, no Facebook... Why so? The code is so simple that I don't even know what I do wrong. Could you help me, please.

@IBAction func shareButtonPressed(sender: AnyObject) {
        let textToShare: String! = "GHJFGEgkjfgejkw"
        let activityViewController: UIActivityViewController = UIActivityViewController(activityItems: [textToShare], applicationActivities: nil)
        activityViewController.excludedActivityTypes = [UIActivityTypeAirDrop, UIActivityTypeMessage, UIActivityTypeMail, UIActivityTypePostToTwitter, UIActivityTypePostToFacebook]    
        self.presentViewController(activityViewController, animated: true, completion: nil)
    }

The problem lies in your code.

    activityViewController.excludedActivityTypes = [UIActivityTypeAirDrop, UIActivityTypeMessage, UIActivityTypeMail, UIActivityTypePostToTwitter, UIActivityTypePostToFacebook]

excludedActivityTypes will exclude these activities from your Activity View Controller.

Try removing UIActivityTypePostToTwitter and UIActivityTypePostToFacebook from excluded activity types.

Just found that issue can occurs because UIActivityViewController doesn't own activityItems array. So just make sure that it remains in memory when you do share action.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM