2016-09-24 59 views
1

我提到了很多關於這個問題的SO問題,而且大多數似乎都被解決了,因爲OP在模擬器上嘗試而不是真正的設備。UIActivityController分享表是空的

我一直都在嘗試,但所有我看到的是下面的圖像。我之前在不同的項目中使用了相同的代碼,因此不確定發生了什麼問題。所有選項都丟失,更多爲空白。這是在一個真正的設備上,其他應用的分享表格工作正常。

這是我的代碼。我正在使用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

+0

任何幫助與此,任何人? –

+0

確保所有東西都是未包裝的或不是可選的,否則不會讓它在任何地方共享。答案由@marlo提供,低於 –

回答

3

我剛剛解決這個問題,我確信,一切都加入到activityItems是解開/不可選

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) 
+0

完美,像魅力一樣工作。感謝和+1 –

+0

拯救我的一天!好的解決方案 –

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

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

與可選的約束力和追加的項目數組我沒有工作通過拆,給了相同的結果。這是什麼工作:

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) 
相關問題