问题
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:
- Save your photo to photo library
- Take asset url of saved photo
- 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