2016-04-13 26 views
0

Bir base64 görüntüsünü kamera rulosuna kaydetmeye çalışıyorum ve kaydedilen görüntü için URL'yi döndürüyorum. Kod, kamera rulosuna kaydetmeyi başarabildiğim kadarıyla çalışır ancak bir hata görüyorum ve hiçbir URL iade edilmiyor. hatadır:Fotoğraf makinesini rulo konumuna getirin ve URL'yi geri döndürün

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

Benim kodudur:

- (void)saveImageDataToLibrary:(CDVInvokedUrlCommand*)command 
{ 

    __block CDVPluginResult* result = nil; 

    NSData* imageData = [NSData dataFromBase64String:[command.arguments objectAtIndex:0]]; 

    UIImage* image = [[[UIImage alloc] initWithData:imageData] autorelease]; 

    __block PHObjectPlaceholder *placeholderAsset = nil; 

    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ 

     PHAssetChangeRequest *newAssetRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:image]; 

     placeholderAsset = newAssetRequest.placeholderForCreatedAsset; 

    } completionHandler:^(BOOL success, NSError *error) { 
     if(success){ 
      NSLog(@"worked"); 
      PHAsset *asset = [self getAssetFromlocalIdentifier:placeholderAsset.localIdentifier]; 

      PHContentEditingInputRequestOptions *options = [[PHContentEditingInputRequestOptions alloc] init]; 
      options.networkAccessAllowed = YES; //download asset metadata from iCloud if needed 

      [asset requestContentEditingInputWithOptions:options 
       completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) { 
       NSURL *assetURL = contentEditingInput.fullSizeImageURL; 
       NSString* url = [assetURL absoluteString]; 
       NSLog(@"our result is: %@", url); 

       result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:url]; 
       [self invokeCallback:command withResult:result]; 

      }]; 

     } else { 
      NSLog(@"Error: %@", error); 
      result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:error.description]; 
      [self invokeCallback:command withResult:result]; 
     } 
    }]; 

} 

- (void) invokeCallback:(CDVInvokedUrlCommand *)command withResult:(CDVPluginResult *)result { 
    [self.commandDelegate sendPluginResult:result callbackId:command.callbackId]; 
} 

cevap

0

deneyin kullanmak: PHContentEditingOutput

O nesne adlı bir özelliğe sahiptir: renderedContentURL

Kullanımı o PHAsset'inizin uygun URL'sini almak için

Yani URL almak için, kod aşağıdaki gibi görünmelidir:

PHContentEditingOutput *contentEditingOutput = [[PHContentEditingOutput alloc] initWithContentEditingInput:YOUR_PHCONTENTEDITING_INPUT]; 

NSURL *myPHAssetURL = [contentEditingOutput renderedContentURL]; 
İlgili konular