【问题标题】:How to add Instagram activity to UIActivityViewController [duplicate]如何将 Instagram 活动添加到 UIActivityViewController [重复]
【发布时间】:2017-02-07 14:29:39
【问题描述】:

我无法找到将 Instagram 选项添加到 UIActivityViewController 的解决方案。谁能帮忙。谢谢。

【问题讨论】:

  • 贴出你试过的代码。
  • 我尝试了将图像添加到相机胶卷然后打开 Instagram 应用程序的代码。但我无法从 UIActivityViewController 中找到任何代码。
  • 您找到解决方案了吗?我面临同样的问题不知道该怎么办。

标签: ios swift instagram uiactivityviewcontroller


【解决方案1】:

使用这样的东西:

@IBAction func shareOnIntagram(sender: UIButton) {

    let finalImage: UIImage = UIImage.imageWithView(photoView)
    let instagramURL = NSURL(string: "instagram://app")
    if (UIApplication.sharedApplication().canOpenURL(instagramURL!)) {

        let imageData = UIImageJPEGRepresentation(finalImage, 1)
        let captionString = "caption"
        let writePath = (NSTemporaryDirectory() as NSString).stringByAppendingPathComponent("instagram.ig")
        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.photo"
            self.documentController.annotation = NSDictionary(object: captionString, forKey: "InstagramCaption")
            self.documentController.presentOpenInMenuFromRect(self.view.frame, inView: self.view, animated: true)
        }

    } else {
        print(" Instagram is not installed ")
    }
}

要使这段代码工作,不要忘记在 UIViewController 类中添加UIDocumentInteractionControllerDelegate

【讨论】:

  • 我已经尝试过代码。如果已安装,它会打开 instagram 应用程序,而不是 UIActivityViewController。
  • 答案与所问的相去甚远。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-19
相关资源
最近更新 更多