presentOpenInMenu显示尝试在Instagram

时间:2017-11-08 09:13:49

标签: ios swift swift3 instagram ios11

我正在尝试将我的应用程序中的图像分享到Instagram。我已按照此处提到的所有步骤进行操作。 https://www.instagram.com/developer/mobile-sharing/iphone-hooks/

这是我的代码

class ViewController: UIViewController {

lazy private var documentInteractionController = UIDocumentInteractionController()

func shareImageOnInstagram()
{
    let image = UIImage(named: "sample")
    let instagramURL = NSURL(string: "instagram://app")
    if UIApplication.shared.canOpenURL(instagramURL! as URL) {
        let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
        let saveImagePath = (documentsPath as NSString).appendingPathComponent("Image.igo")
        let imageData = UIImagePNGRepresentation(image!)
        do {
          try imageData?.write(to: URL.init(fileURLWithPath: saveImagePath), options: NSData.WritingOptions(rawValue: 0))
        } catch {
            print("Instagram sharing error")
        }
        documentInteractionController.url = URL.init(fileURLWithPath: saveImagePath)
        documentInteractionController.uti = "com.instagram.exclusivegram"
        if !self.documentInteractionController.presentOpenInMenu(from: CGRect.zero, in: self.view, animated: true) {
            print("Instagram not found")
        }
    }
    else {
        print("Instagram not found")
    }
}

@IBAction func onShowInstagramClicked(_ sender: Any)
{
    self.shareImageOnInstagram()
} 
}

在iOS 11.1中,每当调用onShowInstagramClicked时,它会显示所有其他应用程序,包括instagram。

enter image description here

同样的代码在iOS 10.3.2上运行良好并显示instagram(和Notes)

enter image description here

iOS 11还需要额外的东西吗?

0 个答案:

没有答案