0
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\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, 2014 at 2:39

1 Answer 1

1
\$\begingroup\$

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
                                                   contentScale:image.scale];
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .