作者:安徒生笔下苍老了谁1_120 | 来源:互联网 | 2023-02-04 18:42
这个看似简单的问题没有引起人们的注意,获得巨额赏金.
在现代iOS(2017)中,
这实际上是我知道将图像保存到iOS照片系统的唯一方法,并获取文件名/路径.
import UIKit
import Photos
func saveTheImage... () {
UIImageWriteToSavedPhotosAlbum(yourUIImage, self,
#selector(Images.image(_:didFinishSavingWithError:contextInfo:)),
nil)
}
func image(_ image: UIImage, didFinishSavingWithError error: NSError?, contextInfo: UnsafeRawPointer) {
guard error == nil else {
print("Couldn't save the image!")
return
}
doGetFileName()
}
func doGetFileName() {
let fo: PHFetchOptiOns= PHFetchOptions()
fo.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
let r = PHAsset.fetchAssets(with: PHAssetMediaType.image, options: fo)
if let mostRecentThingy = r.firstObject {
PHImageManager.default().requestImageData(
for: mostRecentThingy,
options: PHImageRequestOptions(),
resultHandler: { (imagedata, dataUTI, orientation, info) in
if info!.keys.contains("PHImageFileURLKey") {
let path = info!["PHImageFileURLKey"] as! NSURL
print("Holy cow. The path is \(path)")
}
else { print("bizarre problem") }
})
}
else { print("unimaginable catastrophe") }
}
这有两个问题:
1. WTH?!?
它在赛道条件下失败了.
这是非常笨拙的,并且在许多方面似乎令人担忧.
今天是真的要走了吗?