DS.
DS.

Reputation: 3004

UIActivityController share sheet is blank

I referred to a lot of SO questions regarding this and most seem to be resolved because the OP was trying on simulator and not a real device.

I've been trying on both, but all I see is the image below. I've used the same code with success earlier in a different project, so not sure what is going wrong. All options are missing and More is blank. This is on a real device where other apps' share sheet is working fine.

Here's my code. I'm using Xcode 8.1(beta) and iOS 10.1(beta).

    let objectsToShare = ["My text", URL(string: "http://www.google.com") ] as [Any]
    let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
    activityVC.excludedActivityTypes = [UIActivityType.addToReadingList, UIActivityType.postToVimeo, UIActivityType.print, UIActivityType.saveToCameraRoll]

    activityVC.popoverPresentationController?.sourceView = sender
    self.present(activityVC, animated: true, completion: nil)

enter image description here

Upvotes: 2

Views: 2711

Answers (4)

Sam Bing
Sam Bing

Reputation: 2872

Unwrapping with optional binding and appending the items to the array did not work for me, gave the same results. Here is what worked:

guard let image = UIImage(named: "test.png", let url = URL(string: "https://www.google.com") else { return }

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

Upvotes: 1

user3534305
user3534305

Reputation: 31

I got around this problem like so:

    let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)

    activityVC.excludedActivityTypes = [
        UIActivityType.assignToContact,
        UIActivityType.print,
        UIActivityType.addToReadingList,
        UIActivityType.saveToCameraRoll,
        UIActivityType.openInIBooks,
        UIActivityType(rawValue: "com.apple.reminders.RemindersEditorExtension"),
        UIActivityType(rawValue: "com.apple.mobilenotes.SharingExtension"),
    ]

Upvotes: 0

Wilson
Wilson

Reputation: 9136

I have run your code on my physical device without editing and this is the result probably could help you to figure out the issue:

Result:


Code:

class ViewController: UIViewController {
  
  @IBAction func buttonWasTouched(_ sender: UIButton) {
    let objectsToShare = ["My text", URL(string: "http://www.google.com") ] as [Any]

    let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
    activityVC.excludedActivityTypes = [UIActivityType.addToReadingList, UIActivityType.postToVimeo, UIActivityType.print, UIActivityType.saveToCameraRoll]
    
    activityVC.popoverPresentationController?.sourceView = sender
    self.present(activityVC, animated: true, completion: nil)
  }

}

iPhone 5S real device, OS version:

enter image description here


Xcode version:

enter image description here

Upvotes: 1

Marlo Quidato
Marlo Quidato

Reputation: 573

I just overcome this issue, I made sure that everything added to activityItems are unwrapped/not optional

var activityItems: [Any] = []

if let shareURL = URL(string: shareLink) {
    activityItems.append(shareURL)
}

if let shareImage = getShareScreenShot() {
    activityItems.append(shareImage)
}

activityItems.append(shareMessage)

let activity = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)

Upvotes: 3

Related Questions