Question

I have an array of URL. I am getting this URL from server and want to save that image URL data into my SQL data base so while converting this image URL into data and then save that data into my data base,want to show Progress using UIProgressView.

Please let me know about this.

Was it helpful?

Solution

I got the solution.

ASIHTTPRequest is the best option for that.

For Setup ASIHTTPRequest in your project please check this link

After importing ASIHTTPRequest classes in your project import that two classes ASIHTTPRequest.h and ASINetworkQueue.h in your class then define UIProgressView *proGress & ASINetworkQueue *networkQueue object into your .h file.

now code for .m file is

- (void)viewDidLoad
{
    [super viewDidLoad];

    //adata=[[NSMutableArray alloc] init];

    [[self networkQueue] cancelAllOperations];
    // Creating a new queue each time we use it means we don't have to worry about clearing delegates or resetting progress tracking
    [self setNetworkQueue:[ASINetworkQueue queue]];
    [[self networkQueue] setDelegate:self];
    [[self networkQueue] setDownloadProgressDelegate:pgress];

    [[self networkQueue] setRequestDidFinishSelector:@selector(requestFinished:)];
    [[self networkQueue] setRequestDidFailSelector:@selector(requestFailed:)];
    [[self networkQueue] setQueueDidFinishSelector:@selector(queueFinished:)];

    int i;
    for (i=0; i<2; i++) {
        ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/images/large-image.jpg"]];
        [[self networkQueue] addOperation:request];
    }
    [[self networkQueue] go];

}
- (void)requestFinished:(ASIHTTPRequest *)request
{

    //NSData *response = [request responseData];

    if ([[self networkQueue] requestsCount] == 0) {

        [self setNetworkQueue:nil];
    }
    //... Handle success
    //[adata addObject:response];
    NSLog(@"Request finished =%f",[pgress progress]);
}


- (void)queueFinished:(ASIHTTPRequest *)request
{
    if ([[self networkQueue] requestsCount] == 0) {
        [self setNetworkQueue:nil];
    }
    NSLog(@"Queue finished =%f",[pgress progress]);
    //img.image=[UIImage imageWithData:[adata objectAtIndex:0]];
}

- (void)requestWentWrong:(ASIHTTPRequest *)request
{
    NSError *error = [request error];
      NSLog(@"error =%@",error);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top