gpt4 book ai didi

ios - 如何在 instagram 中分享图片?Swift

转载 作者:IT王子 更新时间:2023-10-29 05:28:37 24 4
gpt4 key购买 nike

很抱歉没有代码的问题。但我没有找到任何地方可以寻找。我想在 Instagram 中分享带标题的图片?我该怎么做?

任何帮助都会很棒

最佳答案

如果你不想使用UIDocumentInteractionController

SWIFT 5 更新

import Photos
...

func postImageToInstagram(image: UIImage) {
UIImageWriteToSavedPhotosAlbum(image, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
}
@objc func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
if error != nil {
print(error)
}

let fetchOptions = PHFetchOptions()
fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]

let fetchResult = PHAsset.fetchAssets(with: .image, options: fetchOptions)

if let lastAsset = fetchResult.firstObject as? PHAsset {

let url = URL(string: "instagram://library?LocalIdentifier=\(lastAsset.localIdentifier)")!

if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
} else {
let alertController = UIAlertController(title: "Error", message: "Instagram is not installed", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alertController, animated: true, completion: nil)
}

}
}

关于ios - 如何在 instagram 中分享图片?Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31337490/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com