如何在Instagram中分享图像?Swift [英] How to share image in instagram?Swift

查看:284
本文介绍了如何在Instagram中分享图像?Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抱歉没有代码的问题。但我找不到任何地方可以找。
我想在Instagram上分享图片和标题?我该怎么做?

Sorry for the question without a code.But i didn't find anywhere to look for. I want to share image with title in instagram? How can i do that?

任何帮助都会很棒

推荐答案

    class viewController: UIViewController, UIDocumentInteractionControllerDelegate {

    var yourImage: UIImage?
    var documentController: UIDocumentInteractionController!

    func shareToInstagram() {

     let instagramURL = NSURL(string: "instagram://app")

            if (UIApplication.sharedApplication().canOpenURL(instagramURL!)) {

                let imageData = UIImageJPEGRepresentation(yourImage!, 100)

                let captionString = "caption"

           let writePath = (NSTemporaryDirectory() as NSString).stringByAppendingPathComponent("instagram.igo")
           if imageData?.writeToFile(writePath, atomically: true) == false {

                    return

                } else {
   let fileURL = NSURL(fileURLWithPath: writePath)

                    self.documentController = UIDocumentInteractionController(URL: fileURL)

                    self.documentController.delegate = self

                    self.documentController.UTI = "com.instagram.exlusivegram"

                    self.documentController.annotation = NSDictionary(object: captionString, forKey: "InstagramCaption")
                          self.documentController.presentOpenInMenuFromRect(self.view.frame, inView: self.view, animated: true)

                }

            } else {
                print(" Instagram isn't installed ")
            }
        }
     }

    }

现在这仍然不适用于iOS 9,所以你必须去你的应用程序info.plist,添加LSApplicationQueriesSchemes类型:数组,并在这种情况下添加URL方案instagram。

Now this still wont work with iOS 9, so you will have to go to your apps info.plist, add "LSApplicationQueriesSchemes" type: Array, and add the URL Scheme in this case "instagram".

这篇关于如何在Instagram中分享图像?Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆