热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

获取保存到相册的图像文件名

如何解决《获取保存到相册的图像文件名》经验,有好办法吗?

这个看似简单的问题没有引起人们的注意,获得巨额赏金.

在现代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?!? 它在赛道条件下失败了.

这是非常笨拙的,并且在许多方面似乎令人担忧.

今天是真的要走了吗?


推荐阅读
author-avatar
安徒生笔下苍老了谁1_120
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有