Reputation: 3004
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)
Upvotes: 2
Views: 2711
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
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
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:
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)
}
}
Upvotes: 1
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