0

I want to display a UIProgressView when the user saves an image to the camera roll.

I need to know how much of the image has been downloaded at a given point to determine what the progress indicator should display. How do I determine this?

I'm doing something like:

- (void)updateSaveProgressBar
{    
  if ([self.saveProgressView progress] < 1) {
    self.saveProgressView.progress = (float)receivedData / (float)totalData;
    [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(updateSaveProgressBar) userInfo:nil repeats:NO];
  }
}

self.saveProgressView is the UIProgressView. In this example, how do I determine the value of receivedData?

Thanks.

Steven
  • 1,049
  • 2
  • 14
  • 32
  • Are you using the `UIImageWriteToSavedPhotosAlbum` function? There is no way to get progress. It should only take a second or two. Just show an activity indicator if you want. – rmaddy Mar 08 '13 at 04:56
  • I am using `UIImageWriteToSavedPhotosAlbum`. Is there another method of saving to camera roll where I can get progress? How does the Dropbox app do it, for example? – Steven Mar 08 '13 at 05:04
  • Also, I'm displaying a smaller version of the image, then offering to save the full size which is still remote. So it would take more than just a few seconds to download, especially if the user is on a poor quality network. – Steven Mar 08 '13 at 05:11
  • 2
    You are confusing two parts of this process. Dropbox is showing a progress bar for the download of the remote file from the Dropbox account to the device. Once the file is local, the progress bar goes away and the save to the camera roll is just a split second. It sounds like you have the same need. Show the progress for the download of the remote file. There is no need to show progress of the actual save to the photo library. – rmaddy Mar 08 '13 at 05:15
  • What are you using to download image ? Are you using NSURLConnection? – βhargavḯ Mar 08 '13 at 05:59

1 Answers1

0

In order to show progress for the remote file download, you have to use async download with NSURLConnection, and update the progress each time the connection receives data (connection:didReceiveData:). After your connection finished successfully, you can call UIImageWriteToSavedPhotosAlbum to save your image to the camera roll. Also, UIImageWriteToSavedPhotosAlbum has callback selector to call when the save is finished, you can use that selector to show the user that all the processes of downloading and saving the image are complete.

UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);

completion selector

- (void)               image: (UIImage *) image
    didFinishSavingWithError: (NSError *) error
                 contextInfo: (void *) contextInfo
{

}

Good Luck!

Fahri Azimov
  • 11,470
  • 2
  • 21
  • 29
  • This seems pretty close to the answer @rmaddy provided above. Marking as correct answer, thanks. – Steven Mar 09 '13 at 19:14