我試過在我的Xcode項目(swift)中包括UIActivityViewController
,但是當我在模擬器中運行應用程序時, UIActivityViewController
不包括共享內容的任何選項(我認爲一旦你有它,你可以得到所有的選項,如「在Facebook上共享」和「分享在Twitter」在Xcode中,UIActivityViewController不顯示任何選項,如在社交媒體上分享,如在Facebook,Twitter等共享
這裏是我的代碼:
import UIKit
class ViewController: UIViewController {
@IBAction func shareTextButton(_ sender: UIButton) {
let text = "This is some text that I want to share."
let textToShare = [ text ]
let activityViewController = UIActivityViewController(activityItems: textToShare, applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
self.present(activityViewController, animated: true, completion: nil)
}
@IBAction func shareImageButton(_ sender: UIButton) {
let image = UIImage(named: "Portrait")
let imageToShare = [ image! ]
let activityViewController = UIActivityViewController(activityItems: imageToShare, applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
self.present(activityViewController, animated: true, completion: nil)
}
}
以下是調試控制檯中出現的內容:
2017年4月5日18:32:AA 34.902268-0700 [26541:4024236] [MC]系統組 爲systemgroup.com.apple.configurationprofiles路徑容器是 /用戶/ cuiboy /庫/開發商/ CoreSimulator /Devices/55F2DE69-127A-4F0E-871F-4E431586D8AF/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles objc [26541]:類PLBuildVersion在 /Applications/Xcode.app/Contents/中實現Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x11a182cc0)and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/開發商/軟件開發工具包/ iPhoneSimulator.sdk /系統/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x119f996f0)。將使用兩者之一。哪一個是未定義的。 2017年4月5日18:32:AA 35.141398-0700 [26541:4024236] [芯] SLComposeViewController extensionIdentifierForActivityType: com.apple.UIKit.activity.PostToTwitter => com.apple.share.Twitter.post 2017- 04-05 18:32:35.141532-0700 AA [26541:4024236] [core] SLComposeViewController extensionIdentifierForActivityType: com.apple.UIKit.activity.PostToFacebook => com.apple.share.Facebook.post 2017-04-05 18:32:35.141629-0700 AA [26541:4024236] [芯] SLComposeViewController extensionIdentifierForActivityType: com.apple.UIKit.activity.PostToWeibo => com.apple.share.SinaWeibo.post 2017年4月5日18: 32:35.141728-0700 AA [26541:4024236] [核心] SLComposeViewController extensionIdentifierForActivityType: com.apple.UIKit.activity.TencentWeibo => com.apple.share.TencentWeibo.post 2017年4月5日18:32:35.141801-0700 AA [26541:4024236] [芯] SLComposeViewController extensionIdentifierForActivityType: com.apple.UIKit.activity.PostToFlickr => com.apple.share.Flickr.post 2017年4月5日18:32:AA 35.141904-0700 [26541:4024236] [芯] SLComposeViewController extensionIdentifierForActivityType: com.apple.UIKit.activity.PostToVimeo => com.apple.share.Vimeo.post 2017-04-05 18:32:35.325040-0700 AA [26541:4024236] [MC]從 讀取私人有效用戶設置。
有人知道什麼是錯?我能做些什麼來使Facebook和Twitter和其他社交媒體選項出現在活動視圖控制器中? 謝謝
我想這些選項會出現在真實設備上 –