ios - MBProgressHUD not updating progress -


i importing multiple photos photos library , want show progress using mbprogresshud. using qbimagepickercontroller import photos. photos imported successfully. progress bar in mbprogresshud not updating. following code

-(void)qb_imagepickercontroller:(qbimagepickercontroller *)imagepickercontroller didselectassets:(nsarray *)assets {    if (imagepickercontroller.filtertype == qbimagepickercontrollerfiltertypephotos) {     mbprogresshud *hud = [mbprogresshud showhudaddedto:self.navigationcontroller.view animated:yes];]      // set determinate mode show task progress.     hud.mode = mbprogresshudmodedeterminatehorizontalbar;     hud.delegate = self;      hud.labeltext = nslocalizedstring(@"importing photos", nil);     hud.dimbackground = yes;     hud.detailslabelfont = [uifont systemfontofsize:12.0f];     hud.detailslabeltext = nslocalizedstring(@"please wait...", nil);     hud.progress = 0.0f;      [self importphotosforarray:assets];    }     [self dismissimagepickercontroller]; }   - (void) importphotosforarray:(nsarray *)info {        (alasset *selectedimageasset in info) {        alassetslibrary *assetslibrary = [[alassetslibrary alloc] init];     [assetslibrary assetforurl:[selectedimageasset defaultrepresentation].url resultblock: ^(alasset *asset){         alassetrepresentation *representation = [asset defaultrepresentation];         cgimageref imageref = [representation fullresolutionimage];         if (imageref) {             uiimage *image = [uiimage imagewithcgimage:imageref];             nsdata *imagedata = uiimagejpegrepresentation(image, 1.0);              // create file name image             nsdateformatter *dateformatter = [[nsdateformatter alloc] init];             [dateformatter settimestyle:nsdateformattermediumstyle];             [dateformatter setdatestyle:nsdateformattermediumstyle];             nsstring *imagename = [nsstring stringwithformat:@"photo-%@.png", [dateformatter stringfromdate:[nsdate date]]];             // full path file             nsstring *fullpathtofile = [self.folder.fullpath stringbyappendingpathcomponent:imagename];             // write out data.             [imagedata writetofile:fullpathtofile atomically:no];              sleep(1.0);             progress = ++index/[info count];              [mbprogresshud hudforview:self.navigationcontroller.view].progress = progress;              if (progress >= 1.0) {                 [[mbprogresshud hudforview:self.navigationcontroller.view] hide:yes];                     [self reloaddata];             }         }     } failureblock: ^(nserror *error){         // handle failure.         nslog(@"failure");     }];    } } 

try code. replace importphotosforarray method following.

- (void) importphotosforarray:(nsarray *)info { dispatch_async(dispatch_get_global_queue(qos_class_user_initiated, 0), ^{     __block float progress = 0.0f;     __block float index = 0.0f;      (alasset *selectedimageasset in info) {         alassetrepresentation *representation = [selectedimageasset defaultrepresentation];         cgimageref imageref = [representation fullresolutionimage];         if (imageref) {             uiimage *image = [uiimage imagewithcgimage:imageref];             nsdata *imagedata = uiimagepngrepresentation(image);              // create file name image             nsdateformatter *dateformatter = [[nsdateformatter alloc] init];             [dateformatter settimestyle:nsdateformattermediumstyle];             [dateformatter setdatestyle:nsdateformattermediumstyle];             nsstring *imagename = [nsstring stringwithformat:@"photo-%@.png", [dateformatter stringfromdate:[nsdate date]]];             // full path file             nsstring *fullpathtofile = [self.folder.fullpath stringbyappendingpathcomponent:imagename];             // write out data.             [imagedata writetofile:fullpathtofile atomically:yes];              sleep(1);              progress = ++index/[info count];              dispatch_async(dispatch_get_main_queue(), ^{                 // instead have passed reference hud                 // hud myprogresstask method parameter.                 [mbprogresshud hudforview:self.navigationcontroller.view].progress = progress;             });              if (progress >= 1.0) {                 dispatch_async(dispatch_get_main_queue(), ^{                     // instead have passed reference hud                     // hud myprogresstask method parameter.                     [[mbprogresshud hudforview:self.navigationcontroller.view] hide:yes];                     [self reloaddata];                 });             }         }     } }); 

}


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -