Следующий код никогда не вызывает обратный вызов для экспорта. Сеанс экспорта создается просто отлично. Я не вижу ошибки и никакого прогресса. ЦП составляет 0%. Я не вижу никаких исключений. Состояние равно 1 (в процессе), прогресс равен 0, ошибка равна нулю. Видео воспроизводится в галерее. Я могу успешно получить изображение для видео. Я извлек код в один UIViewController для тестирования, см. Ниже:AVAssetExportSession.requestExportSession callback никогда не вызывал (swift 3, iOS10)
Я тестировал с помощью iOS10.1.1 с видео, которое я записал на iPad.
import UIKit
import Photos
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: Properties
@IBOutlet weak var button: UIButton!
// MARK: Actions
@IBAction func onPress(_ sender: UIButton) {
requestGalleryPermission() {
(_ hasPermission: Bool) in
if hasPermission {
// fetch the asset from Photos
let fetchResult = PHAsset.fetchAssets(withLocalIdentifiers: ["9FFAD8B5-0941-4A95-830F-4ACFA563B71B/L0/001"], options: nil)
// if we successfully fetched the asset...
if let asset = fetchResult.firstObject {
self.exportAsset(asset)
}
}
}
}
func exportAsset(_ asset: PHAsset) {
let tempFilename = "full_sized_image.mov"
var tempURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true).appendingPathComponent(tempFilename)
tempURL = tempURL.standardizedFileURL
let options = PHVideoRequestOptions()
options.deliveryMode = .highQualityFormat
options.isNetworkAccessAllowed = true
// remove any existing file at that location
do {
try FileManager.default.removeItem(at: tempURL)
}
catch {
// most likely, the file didn't exist. Don't sweat it
}
PHImageManager.default().requestExportSession(forVideo: asset, options: options, exportPreset: AVAssetExportPresetHighestQuality) {
(exportSession: AVAssetExportSession?, _) in
if exportSession == nil {
print("COULD NOT CREATE EXPORT SESSION")
return
}
exportSession!.outputURL = tempURL
exportSession!.outputFileType = AVFileTypeQuickTimeMovie
print("GOT EXPORT SESSION")
exportSession!.exportAsynchronously() {
print("COMPLETION HANDLER!!!!")
}
print("progress: \(exportSession!.progress)")
print("error: \(exportSession!.error)")
print("status: \(exportSession!.status.rawValue)")
}
}
func requestGalleryPermission(_ completionHandler: @escaping (_ hasPermission: Bool) -> Void) {
let authorizationStatus = PHPhotoLibrary.authorizationStatus()
if authorizationStatus == .denied || authorizationStatus == .restricted {
completionHandler(false)
}
else if authorizationStatus == .authorized {
completionHandler(true)
}
else {
// ask for authorization
PHPhotoLibrary.requestAuthorization({ (status: PHAuthorizationStatus) in
// if the user gave us authorization...
if status == .authorized {
print("User gave authorization")
completionHandler(true)
}
else {
print("User denied authorization")
completionHandler(false)
}
})
}
}
}
Это было «исцелено», перезагрузив устройство и переключив настройки iCloud. Есть ли что-то, что связано с iCloud, которое будет поддерживать exportAsync в работе над локальным файлом? –