iOS:在社交网络*享图像Swift
问题描述:
我在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
未打开。
我不知道如何解决这个问题?请引导我。
答
请确保您已在文件中设置LSApplicationQueriesSchemes
条目,并声明它尝试查询哪些方案。
<key>LSApplicationQueriesSchemes</key>
<array>
<string>whatsapp</string>
<string>instagram</string>
</array>
不包含“://”。
如果您确实包含“://”canOpenUrl:will return NO。当您实际调用canOpenUrl时:仍必须包含冒号,即canOpenUrl:@"instagram:"
您可以在this WWDC 2015 video中找到更多信息。
而且,这条线是可疑:
var instagramURL: NSURL = NSURL(string: "instagram://user?username=USERNAME")
我怀疑你没有从Instagrams documentation复制此。如果是这样,请用您的实际用户名替换USERNAME
。
要找出错误,你可能想先尝试一个简单的网址:
var instagramURL: NSURL = NSURL(string: "instagram://app")
见:http://*.com/a/30988328/1457385 – shallowThought
LSApplicationsQueriesSchemes? Info.plist在哪里?我无法找到它。 –
如果你在你的if语句中放置了断点,它是否曾经打过它? – colinrf