UIDocumentInteractionController仅在应用程序

时间:2018-03-19 12:35:32

标签: ios swift instagram instagram-api

我正在尝试使用UIDocumentInteractionController将我的iOS应用中的照片分享到Instagram应用,我想在popover中仅显示Instagram应用。由于Instagram描述here它可能但它对我不起作用,我不知道我错过了什么。

以下是Instagram的屏幕截图,确认了它的可能性。

enter image description here

以下是我正在使用的代码。

@IBAction func sharePhoto(btn: UIButton) {

    let photoBundlePath = Bundle.main.url(forResource: "Photo", withExtension: ".png")
    do {
        let data = try Data(contentsOf: photoBundlePath!)
        let fileSavedPath = saveFile(data: data, name: "photo", fileExtension: ".igo")

        let instagramUrl = URL(string: "instagram://app")
        if UIApplication.shared.canOpenURL(instagramUrl!) {
            ic = UIDocumentInteractionController(url: fileSavedPath)
            ic.delegate = self
            ic.uti = "com.instagram.exclusivegram"
            ic.presentOptionsMenu(from: btn.frame, in: self.view, animated: true)
            ic.annotation = ["InstagramCaption" : "Testing"]
        } else {
            print("Instagram is not present in your device")
        }
    } catch  {
        print(error)
    }
}



    func saveFile(data: Data, name: String, fileExtension: String) -> URL {

    let fileManager = FileManager.default
    let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
    let documentDirectory = paths[0]
    let fullPath = documentDirectory + "/" + name + fileExtension

    fileManager.createFile(atPath: fullPath, contents: data, attributes: nil)

    return URL(fileURLWithPath: fullPath)

}
  • 此处还有一件事是为什么Instagram会显示文字" 复制到"如下图所示。

enter image description here

0 个答案:

没有答案