为什么PHPhotoLibrary performChanges creationRequestForAssetFromVideoAtFileURL这么慢?

时间:2015-08-07 20:27:38

标签: ios swift mobile photokit

我的测量时间从几十秒到几分钟,具体取决于视频的大小。这个更改请求是否应该快速(本地闪存盘复制/元数据/校验和),因为它将本地视频添加到photolibrary /相机胶卷? 当打开iCloud备份时,似乎会出现此问题。我无法通过网络搜索或apple dev文档找到更多有用的信息。

示例代码:

    func exportAssetToPhotoLibrary(videoURL: NSURL, _ exportedAsset: (localIdentifier: String) -> Void) {
        var localIdentifier = ""
        var startTime = NSDate.timeIntervalSinceReferenceDate()
        PHPhotoLibrary.sharedPhotoLibrary().performChanges({
            let assetRequest = PHAssetChangeRequest.creationRequestForAssetFromVideoAtFileURL(videoURL)
            let assetPlaceholder = assetRequest.placeholderForCreatedAsset
            localIdentifier = assetPlaceholder.localIdentifier
        },
        completionHandler: { success, error in
                var elapsedTime: NSTimeInterval = NSDate.timeIntervalSinceReferenceDate() - startTime
                NSLog("exported cameo video to photo library \(elapsedTime)")
                exportedAsset(localIdentifier: localIdentifier)
        })
    }

0 个答案:

没有答案