ios - App freezes until image is downloaded and shown. Parse -
i using parse.com when download pffile(contains image) in viewdidappear app freezes while , shows pic. not right. want uiactivityindicatorview animated or @ least shown. know deals async or something. have no idea how make work correctly.
pffile* imagefile = [[pfuser currentuser] objectforkey:@"profilepic"]; if (imagefile) { self.activity.hidden = no; [self.activity startanimating]; nsurl* imagefileurl = [[nsurl alloc]initwithstring:imagefile.url]; nsdata* imagedata = [nsdata datawithcontentsofurl:imagefileurl]; self.profilepic.image = [uiimage imagewithdata:imagedata]; }
this downloads image , shows it.
upd:
pfquery* query = [pfuser query]; [query valueforkey:@"profilepic"]; [query findobjectsinbackgroundwithblock:^(nsarray* data, nserror* error) { pffile* imagefile = data[0]; [imagefile getdatainbackgroundwithblock:^(nsdata* data,nserror* error){ if (!error) { self.activity.hidden = no; [self.activity startanimating]; nsurl* imagefileurl = [[nsurl alloc]initwithstring:imagefile.url]; nsdata* imagedata = [nsdata datawithcontentsofurl:imagefileurl]; self.profilepic.image = [uiimage imagewithdata:imagedata]; }else{ self.profilepic.image = [uiimage imagenamed:@"profile@2.png"]; } }]; }];
upd 2:
this solved problem. both answers helpful.
pfquery* query = [pfuser query]; [query getobjectinbackgroundwithid:[pfuser currentuser].objectid block:^(pfobject* object, nserror* error){ if(!error){ pffile* imagefile = object[@"profilepic"]; [imagefile getdatainbackgroundwithblock:^(nsdata* data, nserror* error) { if (!error) { self.activity.hidden = no; [self.activity startanimating]; self.profilepic.image = [uiimage imagewithdata:data]; nslog(@"profile pic shown"); } else{ nslog(@"error 2: %@",error); } }]; }else{ self.profilepic.image = [uiimage imagenamed:@"profile@2.png"]; nslog(@"fail 1 : %@",error); } }];
this because not getting object in background. try using query accomplish this. if need more info can give full query have code inside app :)
sample code:
[query findobjectsinbackgroundwithblock:^(nsarray *objects, nserror *error) {}];
to image data:
pffile *imagefile = [object objectforkey:@"yourkey"]; [imagefile getdatainbackgroundwithblock:^(nsdata *data, nserror *error) {}];
Comments
Post a Comment