please help with this handler issue
please help with this handler issue
- Subject: please help with this handler issue
- From: "Rick C." <email@hidden>
- Date: Thu, 29 Aug 2013 11:18:43 +0800
Hi,
Not sure why I am struggling here but if someone could assist me that would be great. In one part of my code I'm calling this:
[prefs setObject:[self userImage:[i valueForKey:@"username"] whichAccount:i] forKey:@"User Image"];
Which will in turn call this:
- (UIImage *)userImage:(NSString *)name whichAccount:(id)account
{
__block UIImage *image;
__block UIImage *result;
// had to change this to new api: (6/2013)
NSURL *url =
[NSURL URLWithString:@"http://api.twitter.com/1.1/users/show.json"];
NSDictionary *params = [NSDictionary dictionaryWithObject:name
forKey:@"screen_name"];
TWRequest *request2 = [[TWRequest alloc] initWithURL:url
parameters:params
requestMethod:TWRequestMethodGET];
[request2 setAccount:account];
[request2 performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if (responseData) {
NSDictionary *user =
[NSJSONSerialization JSONObjectWithData:responseData
options:NSJSONReadingAllowFragments
error:NULL];
NSString *profileImageUrl = [[user objectForKey:@"profile_image_url"] stringByReplacingOccurrencesOfString:@"_normal" withString:@""];
NSData *imageData =
[NSData dataWithContentsOfURL:
[NSURL URLWithString:profileImageUrl]];
image = [UIImage imageWithData:imageData];
UIGraphicsBeginImageContext(CGSizeMake(128 ,128));
[image drawInRect:CGRectMake(0, 0, 128, 128)];
result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
}];
// new way:
while (result == nil)
{
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
}
UIImage *OrigImage = result;
UIImage *mask = [UIImage imageNamed:@"email@hidden"];
UIImage *maskedImage = [UIImage maskImage:OrigImage withMask:mask];
return maskedImage;
}
But this is an unreliable way to do this I know because I have problems. Can someone please help me with the right way? Because I need for it to wait before advancing or else it will cause problems in following code. Really appreciate the time thanks!
rc
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden