Berechnen der Dateigröße vor dem download

Was ich will zu tun ist, erklärt sich wie folgt.

Ich habe eine url der MP3-Datei. ( zum Beispiel Sound-Datei )

Wenn der Benutzer die Anwendung startet, sollte das herunterladen zu starten & dafür habe ich implementiert folgende Methoden:

-(void)viewDidLoad {
    [super viewDidLoad];
    NSURL *url=[NSURL URLWithString:@"http://xyz.pqr.com/abc.mp3"];
    NSURLRequest *req=[NSURLRequest requestWithURL:url cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:120];

    NSURLConnection *con=[[NSURLConnection alloc] initWithRequest:req delegate:self startImmediately:YES];

    if(con){
        myWebData=[[NSMutableData data] retain];
        } else {
        //         [MainHandler performSelector:@selector(targetSelector:) withObject:nil];
      } 
     }


-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{

    NSLog(@"%@",@"connection established");
    [myWebData setLength: 0];

}

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    NSLog(@"%@",@"connection receiving data");
    [myWebData appendData:data]; 
}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    NSLog(@"%@",@"connection failed");
    [connection release];
    // [AlertViewHandler showAlertWithErrorMessage:@"Sorry, there is no network connection. Please check your network and try again."];
// [self parserDidEndDocument:nil];
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
    [connection release];
}

Oben genannten Methoden funktionieren perfekt zum herunterladen. Aber ich kann nicht die genaue Größe, die gehen, um heruntergeladen werden. Ich will wissen, was ist die Größe der Datei, die gehen, um download.

Schreibe einen Kommentar