UIActivityController共享表是空白的

时间:2016-09-24 17:55:41

标签: swift3 ios10 uiactivityviewcontroller

我提到了很多关于此问题的SO问题,而且大多数似乎都得到了解决,因为OP正在尝试模拟器而不是真正的设备。

我一直在尝试两者,但我看到的只是下图。我之前在不同的项目中使用了相同的代码,因此不确定出了什么问题。缺少所有选项,更多是空白。这是在一个真实的设备上,其他应用程序的共享表工作正常。

这是我的代码。我正在使用Xcode 8.1(测试版)和iOS 10.1(测试版)。

    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

3 个答案:

答案 0 :(得分:3)

我刚刚克服了这个问题,我确保添加到activityItems的所有内容都是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)

答案 1 :(得分:0)

我已在我的物理设备上运行您的代码而不进行编辑,结果可能会帮助您找出问题所在:

结果:

代码:

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真实设备,操作系统版本:

enter image description here

Xcode版本:

enter image description here

答案 2 :(得分:0)

我解决了这个问题:

    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"),
    ]