我試圖在Instagram,Facebook,Twitter和本地服務(如Mail,Messages,....)上共享視頻和文本....我無法圖如何讓Instagram和Twitter在共享操作單中出現:使用UIActivityViewController在Twitter,Instagram和其他服務上分享視頻和文本
如果我將一組文本和一個URL作爲活動項傳入控制器,只顯示Instagram,但不顯示Twitter。
let url: NSURL = NSURL() // a url that directs to a video
let items: [AnyObject] = ["Check out this video", url]
let shareable = UIActivityViewController(activityItems: items, applicationActivities: nil)
controller.presentViewController(shareable,
animated: true,
completion: nil)
如果我創建一個實現UIActivityItemSource協議而不是和使用,作爲activityItems,只是Twitter的顯示出來,而不是Instagram的一類:
class VideoActivityItemSource: NSObject, UIActivityItemSource {
private let videoUrl: NSURL
private let shareText = "View the full video here!"
init(url: NSURL) {
self.videoUrl = url
}
func activityViewControllerPlaceholderItem(activityViewController: UIActivityViewController) -> AnyObject {
return ""
}
func activityViewController(activityViewController: UIActivityViewController, itemForActivityType activityType: String) -> AnyObject? {
switch activityType {
case UIActivityTypePostToFacebook:
return self.videoUrl
case UIActivityTypeMail:
return self.videoUrl
default:
return ["text": self.shareText, "url": self.videoUrl]
}
}
func activityViewController(activityViewController: UIActivityViewController, subjectForActivityType activityType: String?) -> String {
return "Hey check this new cool app!!!"
}
func activityViewController(activityViewController: UIActivityViewController, thumbnailImageForActivityType activityType: String?, suggestedSize size: CGSize) -> UIImage? {
return nil
}
}
,然後通過這個更換項目:
items = [VideoActivityItemSource(url: url)]
我不知道爲什麼在這種情況下Twitter不會顯示在操作表中。有人有一個想法如何解決這個問題嗎?
Have you shared in Instagram?我無法分享。我沒有顯示Instagram圖標 –
如果手機上安裝了Instagram,當我測試時,它會顯示一個圖標。 – bughana