2016-07-19 77 views
1

我正在使用下面的代碼將視頻保存到照片庫。iOS 9 PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:失敗,錯誤代碼爲-1

NSString *ss = [finalVideoURL path]; 

    __block PHObjectPlaceholder *placeholder; 


    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ 
     PHAssetChangeRequest* createAssetRequest = [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:[NSURL fileURLWithPath:ss]]; 
     _placeholder = [createAssetRequest placeholderForCreatedAsset]; 

    } completionHandler:^(BOOL success, NSError *error) { 
     if (success) 
     { 

      NSLog(@" success iOS 9"); 
     } 
     else 
     { 
      NSLog(@"%@", error); 
     } 
    }]; 

此代碼工作很好地iOS 8.x. 但它失敗,錯誤代碼-1 iOS 9.x。 錯誤是

`Error Domain=NSCocoaErrorDomain Code=-1 "(null)"` 

有關此問題在iOS中9.任何想法? 任何幫助表示讚賞! 感謝

回答

0

只能保存在自己的專輯 你需要創建一個相冊

//獲取自定義相冊 
- (PHAssetCollection *)getAPPCollection { 
// Getting the app album if any: 找是否已經創建自定義相冊 
PHFetchResult<PHAssetCollection *> *collectionResult = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil]; 
NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]; 
for (PHAssetCollection *collection in collectionResult) { 
    if ([collection.localizedTitle isEqualToString:appName]) { 
     return collection; 
    } 
} 

// Creating the album: 新建自定義相冊 
__block NSString *collectionId = nil; 
NSError *error = nil; 
[[PHPhotoLibrary sharedPhotoLibrary] performChangesAndWait:^{ 
    collectionId = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:appName].placeholderForCreatedAssetCollection.localIdentifier; 
} error:&error]; 
if (error) { 
    NSLog(@"創建相冊:%@失敗", appName); 
    return nil; 
} 
return [PHAssetCollection fetchAssetCollectionsWithLocalIdentifiers:@[collectionId] options:nil].lastObject; 
} 
+0

請讓你的代碼的正確的縮進... http://meta.stackexchange.com/questions/ 22186 /如何-DO-格式,我的代碼塊 –

相關問題