लाभ यह प्रतीत होता है आसान सवाल कोई ध्यान नहीं है के साथ एक बहुत बड़ा इनाम सहेजी गई छवि का फ़ाइल नाम प्राप्त करें।फ़ोटो एल्बम
आधुनिक आईओएस (2017) में,
यहाँ वास्तव में एक ही रास्ता मैं जानता हूँ कि आईओएस फ़ोटो प्रणाली के लिए एक छवि बचाने के लिए, और फ़ाइल नाम/पथ प्राप्त करने के लिए है।
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?!?
2. यह दौड़ का मैदान की स्थिति में विफल रहता है।
यह आश्चर्यजनक बोझल है, और यह कई तरीकों से में worrysome लगता है।
यह वास्तव में आज जाने का रास्ता, है?
क्या आपको वास्तव में यूआरएल की आवश्यकता है? क्या आप संबंधित 'PHObject' की 'localIdentifier' प्रॉपर्टी का भी उपयोग कर सकते हैं? –