Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-03-2010, 04:57 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 1
fabio1979 is on a distinguished road
Default best way to know the time of upload/download of a file from/onto iPhone

Hi

I'm trying to get the time interval I need to download/upload something to/from a server with no password/proxy. I found a method used by ericasadun. Which actually prints the time iPhone needed to download a certain file.

Code:
- (void) getData: (NSNumber *) which
    {
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
        self.log = [NSMutableString string];
        [self doLog:@"Downloading data now...\n"];
        NSDate *date = [NSDate date];

        NSArray *urlArray = [NSArray arrayWithObjects: SMALL_URL, BIG_URL, FAKE_URL, nil];
        NSURL *url = [NSURL URLWithString: [urlArray objectAtIndex:[which intValue]]];
        NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
        NSURLResponse *response;
        NSError *error;
        NSData* result = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];
        [self doLog:@"Response expects %d bytes", [response expectedContentLength]];
        [self doLog:@"Response suggested file name: %@", [response suggestedFilename]];
        if ([response suggestedFilename])
            self.savePath = [DEST_PATH stringByAppendingString:[response suggestedFilename]];

        if (!result)
            [self doLog:@"Error downloading data: %@.", [error localizedDescription]];
        else if ([response expectedContentLength] < 0)
            [self doLog:@"Error with download. Carrier redirect?"];
        else
        {
            //NSLog(@"Elapsed time: %0.2f seconds.", -1*[date timeIntervalSinceNow]);

            //textView.text = @"Elapsed time: %0.2f seconds.", -1*[date timeIntervalSinceNow];

            [self doLog:@"Download succeeded."];
            [self doLog:@"Read %d bytes", result.length];
            [self doLog:@"Elapsed time: %0.2f seconds.", -1*[date timeIntervalSinceNow]];
            [result writeToFile:self.savePath atomically:YES];
            [self doLog:@"Data written to file: %@.", self.savePath];
        }

        [self performSelectorOnMainThread:@selector(finishedGettingData) withObject:nil waitUntilDone:NO];
        [pool release];
    }
I'd like to know if in your opinion this is the best way to do it (also for FTP connections).

Also, about upload, is there any similar solution? I thought on

Code:
- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
and to get the time needed with the same solution of above.
Are these the right directions both for http sand ftp? I'm not asking for code or something similar, just for someone saying to me, this is the right direction!

Thanks!
fabio1979 is offline   Reply With Quote
Old 06-03-2010, 07:29 AM   #2 (permalink)
Registered Member
 
Join Date: Nov 2009
Age: 26
Posts: 57
asrekik is on a distinguished road
Default

First of all, i inform you , that i don't try FTP connection in iphone, but here is my opinion:

Quote:
Originally Posted by fabio1979 View Post
Are these the right directions both for http sand ftp? I'm not asking for code or something similar, just for someone saying to me, this is the right direction!
I think that it's yes, because, according to URL Loading System Programming Guide http://developer.apple.com/iphone/li...dingSystem.pdf, the URL loading system supports these protocols: http, ftp, https, and file. SO all the method emains functional for HTTP and FTP connection.I don't find a problem using FTP.
asrekik is offline   Reply With Quote
Old 06-04-2010, 06:25 AM   #3 (permalink)
Registered Member
 
Join Date: Nov 2009
Age: 26
Posts: 57
asrekik is on a distinguished road
Default

here is a sample http://developer.apple.com/iphone/li...id/DTS40009243that uses FTP Connexion, i hope that it can help you

Last edited by asrekik; 06-08-2010 at 03:05 AM.
asrekik is offline   Reply With Quote
Reply

Bookmarks

Tags
download, ftp, iphone, nsurlconnect, upload

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 352
13 members and 339 guests
ajay123123, Anwerbl, Arty Tales, ashaman64, baja_yu, ChrisYates, HemiMG, mini998, mottdog, newDev, Objective Zero, oceanlablight, Steven.C
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,878
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:59 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0