objective-c - iOS6 UIImage 导致崩溃

标签 objective-c uiimage ios6

自 iOS6 以来,我遇到了 UIImages 的一个非常奇怪的问题,导致应用程序崩溃。 完整的方法是这样的:

NSURL *url = [NSURL URLWithString:@"http://api.twitter.com/1/users/show.json"];

NSDictionary *parametros = [NSDictionary dictionaryWithObjectsAndKeys:account.username, @"screen_name", nil];

SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter
                            requestMethod:SLRequestMethodGET
                            URL:url
                            parameters:parametros];
[request setAccount:account];
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
        if ([urlResponse statusCode] == 200) {
            NSError *error_ = nil;
            NSDictionary *userInfo = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error_];
            UIImage *image = [UIImage imageWithData:[userInfo objectForKey:@"profile_image_url"]];
            UIImage *image = [UIImage imageWithData:[userInfo objectForKey:@"profile_image_url"]];
            dispatch_sync(dispatch_get_main_queue(), ^{
                [_imageCache setObject:image forKey:account.username];
                [ListAccount reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:NO];
            });
        }
    }];

问题出现在这一行

UIImage *image = [UIImage imageWithData:[userInfo objectForKey:@"profile_image_url"]];

这在 iOS5 中没有问题。我似乎找不到原因或遇到同样问题的人。任何建议将不胜感激

崩溃如下:

2012-09-28 17:30:53.600 Catalogo[7321:c07] -[__NSCFString bytes]: unrecognized selector     sent to instance 0x10eaf180
2012-09-28 17:30:53.601 Catalogo[7321:c07] *** Terminating app due to uncaught exception     'NSInvalidArgumentException', reason: '-[__NSCFString bytes]: unrecognized selector sent to     instance 0x10eaf180'
*** First throw call stack:
(0x2aed012 0x1a28e7e 0x2b784bd 0x2adcbbc 0x2adc94e 0x2a75390 0x203630c 0x2035e7e 0x2035d98     0x10dc23d 0xf991f3 0xf98ef4 0x6c54e 0x1b9e731 0x1bad014 0x1b9d7d5 0x2a93af5 0x2a92f44     0x2a92e1b 0x2dd87e3 0x2dd8668 0xf7765c 0x79cd 0x2d45)
libc++abi.dylib: terminate called throwing an exception

以下内容:

[userInfo objectForKey:@"profile_image_url"]

返回 Twitter 个人资料图像的 URL

最佳答案

您需要将 [userInfo objectForKey:@"profile_image_url"] 转换为 NSData,然后将其传递给 imageWithData:.

NSString * profileImageString = [userInfo objectForKey:@"profile_image_url"];
NSData * profileImageData = [profileImageString dataUsingEncoding:NSUTF8StringEncoding];

比使用:

UIImage *image = [UIImage imageWithData:profileImageData];

关于objective-c - iOS6 UIImage 导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12646913/

相关文章:

iphone - 无法从数据库 ios 中删除数据

ios - 检测 iOS 上的向上滑动手势

objective-c - 使用从 UIImagePickerController 保存的图像进行内存管理

ios - Xcode 9.2 : missing required architecture arm64 in file/. ......./libPaymentsSDK.a(2 片)

ios - 像 Mail App 这样的 UITextView 的滑动/拖动手势

ios - 带有 Swift 3 的 APAddressBook - EXC_ARM_BREAKPOINT

ios - UIImageView 没有正确释放图像数据?

iphone - 像 camscanner 一样裁剪 UIImage

ios - 向 UIImage 添加宽度?

ios - 抓取 iPhone screenWidth 和 Height 以实现可重用性