I'm trying to get the profile picture from Facebook, but I'm getting the following error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage stringByStandardizingPath]:

This is my code:

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://graph.facebook.com/%@/picture?type=square", userid]];
 NSData *data = [NSData dataWithContentsOfURL:url];
 UIImage *image = [UIImage imageWithData:data];
 //convert UIImage to CCSprite
 CCTexture *texture = [CCTexture textureWithFile:image];
 CCSprite *sprite = [CCSprite spriteWithTexture:texture];
 sprite.position = ccp(winWidth*.5, winHeight*.5);

The error occurs in the UIImage *image line.

  • \$\begingroup\$ The error looks odd, but nevertheless you should check data for nil before passing it to UIImage, in case dataWithContentsOfURL has failed. \$\endgroup\$ – glampert May 3 '14 at 2:39

That error occurs on this line:

CCTexture *texture = [CCTexture textureWithFile:image];

And this is the right way to do this:

CCTexture *texture = [[CCTexture alloc] initWithCGImage:image.CGImage

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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