使用UIDocumentInteractionController分享图片到Instagram

这次做的项目中需要分享图片到Instagram,于是看了下Instagram的官方文档,要分享图片到Instagram必须使用UIDocumentInteractionController。于是写了一个,废话少说,直接上代码

if let docPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first {
    let imagePath = docPath.appending("/share.igo")
    
    if let imageData = UIImagePNGRepresentation(UIImage.init(named: "map_slide_unlock_arrow_icon")!) {
        let nsData: NSData = imageData as NSData
        nsData.write(toFile: imagePath, atomically: true)
        docController = UIDocumentInteractionController(url: URL(fileURLWithPath: imagePath))
        docController?.delegate = self
        docController?.uti = "com.instagram.exclusivegram"
        docController?.url = NSURL.fileURL(withPath: imagePath)
        
        docController?.presentOpenInMenu(from: vc!.view.bounds, in: vc!.view, animated: true)
    }
}

效果如下图所示

Paste_Image.png

值得一提的是我们处于天朝局域网,要想上Instagram必须要翻墙。另外现在是把图片分享过去了,但是不知道怎么设置Instagram默认的描述文字,如果有知道的大神请指点

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容