2

Since iOS6 I have a very weird issue with UIImages that causes the application to crash. The full method is like this:

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

The problem occur in this line

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

This was no problem in iOS5. I can't seem to find why or someone that had the same problem. Any suggestion will be really appreciated

The crash is the following:

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

The following:

[userInfo objectForKey:@"profile_image_url"]

return the url of a twitter profile image

2
  • Could you NSLog userInfo and give information about the error?
    – CSolanaM
    Sep 28, 2012 at 20:45
  • I've edited the post according to your requests Sep 28, 2012 at 22:07

1 Answer 1

2

You need to convert [userInfo objectForKey:@"profile_image_url"] into NSData, then pass it to imageWithData:.

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

Than use:

UIImage *image = [UIImage imageWithData:profileImageData];
3
  • tried: NSData *data = [NSData dataWithContentsOfURL:[userInfo objectForKey:@"profile_image_url"]]; UIImage *image = [UIImage imageWithData:data]; still no luck, this error was thrown: -[__NSCFString isFileURL]: unrecognized selector sent to instance 0xa2218e0 Sep 28, 2012 at 22:16
  • Convert the NSString to NSURL [NSData dataWithContentsOfURL:[NSURL URLWithString:[userInfo objectForKey:@"profile_image_url"]]];
    – WrightsCS
    Sep 28, 2012 at 22:17
  • tried your last edit but still no luck: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCache setObject:forKey:cost:]: attempt to insert nil value (key: enf_4eva)' Sep 28, 2012 at 22:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.