我在swift中運行示例應用程序。我需要分享我的應用程序的圖像。 在Social framework
的幫助下,我整合了Facebook
和Twitter
。現在,我不知道如何與Instagram
和WhatsApp
iOS:在社交網絡中共享圖像Swift
分享按鈕操作
@IBAction func shareAcn(sender: UITapGestureRecognizer) {
var documentController: UIDocumentInteractionController!
let fileURL = NSBundle.mainBundle().pathForResource("smc", ofType: "png")
documentController = UIDocumentInteractionController.init(URL: NSURL(fileURLWithPath: fileURL!))
documentController.presentOptionsMenuFromRect(CGRectZero, inView: self.view, animated: true)
}
整合了WhatsApp
@IBAction func shareAcn(sender: UITapGestureRecognizer) {
var documentController: UIDocumentInteractionController!
let image = UIImage(named: "smc")
let filename = "myimage.wai"
let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, false)[0] as NSString
let destinationPath = documentsPath.stringByAppendingString("/" + filename)
UIImagePNGRepresentation(image!)!.writeToFile(destinationPath, atomically: false)
let fileURL = NSURL(fileURLWithPath: destinationPath) as NSURL
documentController = UIDocumentInteractionController.init(URL: fileURL)
documentController.UTI = "net.whatsapp.image"
documentController.presentOptionsMenuFromRect(CGRectZero, inView: self.view, animated: true)
}
如果我選擇[導入到WhatsApp的或複製到的WhatsApp]應用墜毀。如果我選擇WhatsApp
,「此項目無法發送」。
Instagram的
var instagramURL: NSURL = NSURL(string: "instagram://user?username=USERNAME")
if UIApplication.sharedApplication().canOpenURL(instagramURL) {
UIApplication.sharedApplication().openURL(instagramURL)
}
無代碼工作。
我安裝了Instagram
並作爲我的用戶登錄到我的測試設備中,如果我運行,Instagram
未打開。
我不知道如何解決這個問題?請引導我。
見:http://stackoverflow.com/a/30988328/1457385 – shallowThought
LSApplicationsQueriesSchemes? Info.plist在哪裏?我無法找到它。 –
如果你在你的if語句中放置了斷點,它是否曾經打過它? – colinrf