iPhone - 将相机照片保存到 iPhone 相册时崩溃

发布于 2024-10-27 15:43:47 字数 2654 浏览 2 评论 0原文

我正在用我的应用程序拍照,调用委托方法,图像保存在库中,但日志中出现崩溃错误:

*** 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)。

问题是什么 ?

I'm taking a photo with my app, the delegate method is called, the Image is saved in the library, but I have a crash error in the log :

*** 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'

My code is the following :

- (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 is not nil.
The photoSaved method is declared in the .h
I also tried with @selector(photoSaved:) and @selector(photoSaved).

What is the problem ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请爱~陌生人 2024-11-03 15:43:47

获取选择器的正确方法如下,因为参数名称也是方法名称的一部分:

 @selector(photoSaved:didFinishSavingWithError:contextInfo:)

The proper way to get the selector is as follows, since argument names are also a part of the method name:

 @selector(photoSaved:didFinishSavingWithError:contextInfo:)
白芷 2024-11-03 15:43:47

试试这样:

- (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 );
}

Try it like this:

- (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 );
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文