2011-03-30 68 views
8

我正在與我的應用拍照,調用委託方法,圖像保存在庫中,但日誌中有崩潰錯誤:iPhone - 在將相機圖片保存到iPhone相冊時崩潰

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSInvocation invocationWithMethodSignature:]: method signature argument cannot be nil' 
*** Call stack at first throw: 
(
    0 CoreFoundation      0x33ac0987 __exceptionPreprocess + 114 
    1 libobjc.A.dylib      0x3347b49d objc_exception_throw + 24 
    2 CoreFoundation      0x33a6b05d +[NSInvocation invocationWithMethodSignature:] + 340 
    3 PhotoLibrary      0x3038da11 __-[PLAssetsSaver _createWriteImageCompletionBlockWithImage:target:selector:contextInfo:]_block_invoke_1 + 96 
    4 PhotoLibrary      0x3038d7cd __-[PLAssetsSaver _saveImage:imageData:properties:completionBlock:]_block_invoke_2 + 56 
    5 PhotoLibrary      0x3038de87 __-[PLAssetsSaver queueJobData:requestEnqueuedBlock:completionBlock:imagePort:previewImagePort:]_block_invoke_2 + 122 
    6 libSystem.B.dylib     0x33c32680 _dispatch_call_block_and_release + 20 
    7 libSystem.B.dylib     0x33c32e38 _dispatch_main_queue_callback_4CF + 220 
    8 CoreFoundation      0x33a482ab __CFRunLoopRun + 1334 
    9 CoreFoundation      0x33a47c87 CFRunLoopRunSpecific + 230 
    10 CoreFoundation      0x33a47b8f CFRunLoopRunInMode + 58 
    11 GraphicsServices     0x33b0e4ab GSEventRunModal + 114 
    12 GraphicsServices     0x33b0e557 GSEventRun + 62 
    13 UIKit        0x32099329 -[UIApplication _run] + 412 
    14 UIKit        0x32096e93 UIApplicationMain + 670 
    15 MySoPrettyApp      0x00002737 main + 82 
    16 MySoPrettyApp      0x000026e0 start + 40 
) 
terminate called after throwing an instance of 'NSException' 

我的代碼如下:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
    UIImage *pickedImage = [[info objectForKey:UIImagePickerControllerOriginalImage] retain]; 
    UIImageWriteToSavedPhotosAlbum (pickedImage, self, @selector(photoSaved:::), nil); 
} 

-(void)photoSaved:(UIImage*)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo { 
    if(!error){ 
     NSLog(@"Photo saved to library!"); 
    } else{ 
     NSLog(@"Saving failed :("); 
    } 
} 

pickedImage不爲零。
photoSaved方法在.h
中聲明我也用@selector(photoSaved :)和@selector(photoSaved)嘗試過。

什麼問題?

回答

8

正確的方式來獲得選擇如下,因爲參數名也是方法名稱的一部分:

@selector(photoSaved:didFinishSavingWithError:contextInfo:) 
+0

謝謝你,我沒我不知道。對不起,今晚我的懶惰對於這樣一個簡單的問題。 – Oliver 2011-03-31 00:00:09

4

試試這樣說:

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo 
{ 
    if(!error){ 
     NSLog(@"Photo saved to library!"); 
    } 
    else{ 
    NSLog(@"Saving failed :("); 
    } 
} 

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    UIImage *pickedImage = [[info objectForKey:UIImagePickerControllerOriginalImage] retain]; 
    UIImageWriteToSavedPhotosAlbum(pickedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); 
} 
+0

謝謝你的回答 – Oliver 2011-03-31 00:01:14

+0

沒問題。祝你的項目好運。 – Dmacpro 2011-03-31 00:08:38

+0

感謝他解決了我的問題。 – user366584 2011-12-01 12:47:11