我在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