ios - UIProgressView bar during process -


i want implement progress bar in application. process happening app copying directory ios documents directory. takes anywhere 7-10 seconds (iphone 4 tested). understanding of progress bars update bar things happening. based on copying of directory code, not sure how know how far along is.

can offer suggestions or examples on how can done? progress bar code below , copying of directory code.

thanks!

uiprogressview *progressview = [[uiprogressview alloc] initwithprogressviewstyle:  uiprogressviewstylebar]; progressview.progress = 0.75f; [self.view addsubview: progressview]; [progressview release];    //takes 7-10 seconds. show progress bar code if (![filemanager fileexistsatpath:datapath]) {     nsstring *bundlepath = [[nsbundle mainbundle] bundlepath];     nsstring *imagedatapath = [bundlepath stringbyappendingpathcomponent:_datapath];     if (imagedatapath) {         [filemanager copyitematpath:imagedatapath topath_:datapath error:nil];     } } 

define nstimer *timer in .h file

if (![filemanager fileexistsatpath:datapath]) {     nsstring *bundlepath = [[nsbundle mainbundle] bundlepath];     nsstring *imagedatapath = [bundlepath stringbyappendingpathcomponent:_datapath];     timer = [nstimer timerwithtimeinterval:0.5 target:self selector:@selector(updateprogressview) userinfo:nil repeats:yes];     [timer fire];       if (imagedatapath) {         dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), ^{             [filemanager copyitematpath:imagedatapath topath_:datapath error:nil];         };     } } 

and add method

- (void) updateprogressview{     nsstring *bundlepath = [[nsbundle mainbundle] bundlepath];     nsstring *imagedatapath = [bundlepath stringbyappendingpathcomponent:_datapath];     nsdata *alldata = [nsdata datawithcontentsoffile:imagedatapath];     nsdata *writtendata = [nsdata datawithcontentsoffile:datapath];     float progress = [writtendata length]/(float)[alldata length];     [pro setprogress:progress];     if (progress == 1.0){          [timer invalidate];     } } 

Comments