0 votes
1 view
in Salesforce by (11.9k points)

I am trying to display logged in user's profile picture using the following:

    NSLog(@"url is : %@",[SFAccountManager sharedInstance].idData.pictureUrl);
    profilePicData=[NSData dataWithContentsOfURL:[SFAccountManager sharedInstance].idData.pictureUrl];
    if ( profilePicData )
    {
        NSArray       *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString  *documentsDirectory = [paths objectAtIndex:0];
        NSString  *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"filename.jpg"];
        NSLog(@"pic path:  %@",filePath);
        [profilePicData writeToFile:filePath atomically:YES];
    }
    NSLog(@"pic data:  %@",profilePicData);
}

in NSLog("%@", [NSData dataWithContentsOfURL:[SFAccountManager sharedInstance].idData.pictureUrl]); shows some data but does not display picture in UIImageView.

Any help would be appreciated.

1 Answer

0 votes
by (31.8k points)

I was striving to do exactly the same inside the Chatter API - I needed to load image from feed data under "smallPhotoUrl". What I have found is, that at the end of URL active token has to be added.

This source introduced me to a concept: Accessing Chatter user pics

And I finally was able to find some clear information on how to access that token here: salesforce_platform_mobile_services.pdf page 262

So eventually I did this:

NSString *builtImageUrlWithToken = [NSString stringWithFormat:@"%@?oauth_token=%@",

 phototoUrl, [SFAccountManager sharedInstance].credentials.accessToken];

    NSURL *imageURL = [NSURL URLWithString:builtImageUrlWithToken];

    NSData *imageData = [NSData dataWithContentsOfURL:imageURL];

I think it's relevant to this topic, as I came across it while looking for this particular solution. I am sure it could be useful for others as well.

Thanks!

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...