IOS. Sharing image to Instagram without using a menu display

给你一囗甜甜゛ 提交于 2019-12-11 04:44:43

问题


Can anyone help and explain how to do sharing to Instagram without displaying the menu? For example, the application Prisma does it without using a menu display.


回答1:


You must do this:

  1. Save your photo to photo library
  2. Take asset url of saved photo
  3. Open Instagram through URL Scheme with this URL

instagram://library?AssetPath=ASSET_PATH

Where ASSET_PATH is asset url taken on the second step.

Code example on Swift 3:

let library = ALAssetsLibrary()
library.writeImage(toSavedPhotosAlbum: image.cgImage, metadata: nil) { (url, error) in
    if let url = url {
        DispatchQueue.main.async {
            let path = url.absoluteString.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlQueryAllowed)
            let instagram = URL(string: "instagram://library?AssetPath=\(path)")
            UIApplication.shared.open(instagram!)
        }
    }
}


来源:https://stackoverflow.com/questions/38303413/ios-sharing-image-to-instagram-without-using-a-menu-display

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!