- [NSConcreteMutableData base64EncodedStringWithOptions:]:无法识别的选择器发送到实例0x776e920' [英] -[NSConcreteMutableData base64EncodedStringWithOptions:]: unrecognized selector sent to instance 0x776e920'

查看:498
本文介绍了 - [NSConcreteMutableData base64EncodedStringWithOptions:]:无法识别的选择器发送到实例0x776e920'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用不断崩溃,并显示以下消息:

My app keep crashing with the following message:

* 由于未捕获的异常'NSInvalidArgumentException'而终止应用,原因:' - [ NSConcreteMutableData base64EncodedStringWithOptions:]:无法识别的选择器发送到实例0x776e920'

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteMutableData base64EncodedStringWithOptions:]: unrecognized selector sent to instance 0x776e920'

以下是代码的一部分。任何帮助将不胜感激:

Here is part of the code. Any help will be appreciated:

-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
// Saving the image in the uiimage "myImage".
UIImage *myImage = [info objectForKey:UIImagePickerControllerOriginalImage];

NSString *imageString = [self encodeToBase64String:myImage];
[self dismissViewControllerAnimated:YES completion:NULL];
}

- (NSString *)encodeToBase64String:(UIImage *)image{
    NSString * test = [UIImagePNGRepresentation(image) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
    return test;
}

我已经检查过并且UIImage中有一个图像。谢谢。

I have checked and the UIImage has an image in it. Thanks.

推荐答案

base64EncodedStringWithOptions:从iOS 7和OS开始可用X 10.9。

base64EncodedStringWithOptions: is available starting with iOS 7 and OS X 10.9.

无法识别的选择器异常可能意味着您在早期的iOS版本的
上运行代码,该方法不可用。

The "unrecognized selector" exception probably means that you run the code on an earlier iOS release, where the method is not available.

有第三方库提供类似的方法,如果你必须支持iOS 6或5,可以使用
(例如 https://github.com/nicklockwood/Base64 )。

There are 3rd party libraries available which offer similar methods and can be used instead if you have to support iOS 6 or 5 (for example https://github.com/nicklockwood/Base64).

NSData 文档还说明有一个 base64Encoding 方法
(及其对应的 initWithBase64Encoding:

The NSData documentation also states that there is a base64Encoding method (and its counterpart initWithBase64Encoding:)


虽然此方法仅针对iOS 7公开发布,但它存在
从iOS 4开始;如果您的应用程序需要
定位iOS 7之前的操作系统,则可以使用它。此方法的行为类似于
base64EncodedStringWithOptions:,但忽略所有未知字符。

Although this method was only introduced publicly for iOS 7, it has existed since iOS 4; you can use it if your application needs to target an operating system prior to iOS 7. This method behaves like base64EncodedStringWithOptions:, but ignores all unknown characters.

(所以似乎iOS长时间有一个 NSData 到Base64的转换,但它从来没有
公开记录!)

(So it seems that iOS had a NSData to Base64 conversion for a long time, but it was never publicly documented!)

这篇关于 - [NSConcreteMutableData base64EncodedStringWithOptions:]:无法识别的选择器发送到实例0x776e920'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆