2015-11-03 16 views
11

Für iOS9 ist ALAssetsLibrary veraltet. So, wie man es als PHPPhotoLibrary anstelle von ALAssets ändert?Verwendung von PHPhotoLibrary wie ALAssentsLibrary

if (RecordedSuccessfully && recording == NO) { 
    //----- RECORDED SUCESSFULLY ----- 
    NSLog(@"didFinishRecordingToOutputFileAtURL - success"); 
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; 
    if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:outputFileURL]) 
    { 
     [library writeVideoAtPathToSavedPhotosAlbum:outputFileURL 
            completionBlock:^(NSURL *assetURL, NSError *error) 
     { 
      if (error) 
      { 

      } 
     }]; 
    } 

// Ich habe dies versucht, aber hat nicht funktioniert

[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ 

     PHAssetChangeRequest* createAssetRequest = [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:outputFileURL]; 

     NSParameterAssert(createAssetRequest); 
    } 
             completionHandler:^(BOOL success, NSError *error) {}]; 
    } 
} 

Antwort

16
// Save to the album 
    __block PHObjectPlaceholder *placeholder; 

    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ 
     PHAssetChangeRequest* createAssetRequest = [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:outputFileURL]; 
     placeholder = [createAssetRequest placeholderForCreatedAsset]; 

    } completionHandler:^(BOOL success, NSError *error) { 
     if (success) 
     { 
      NSLog(@"didFinishRecordingToOutputFileAtURL - success for ios9"); 
     } 
     else 
     { 
      NSLog(@"%@", error); 
     } 
    }]; 
+1

dies ist die richtige Antwort, sollten Sie es als solche markieren :) – joey

+0

@deniz Es Fehler Ungültige URL gibt. –

+2

Wie wäre es mit awareURL? Wie kann ich nach dem Speichern eine URL erhalten? – Besat