Quelle est la meilleure façon de convertir NSURLConnection en NSURLSession?De NSURLConnection à NSURLSession
message d'erreur: (Xcode)
ViewController.m: 342: 45: 'stringByAddingPercentEscapesUsingEncoding:' est obsolète: première obsolète dans iOS 9.0 - Utilisez -stringByAddingPercentEncodingWithAllowedCharacters: à la place, qui utilise toujours recommandé UTF 8 codage, et qui code pour un composant ou un sous-composant d'URL spécifique puisque chaque composant ou sous-composant d'URL a des règles différentes pour les caractères valides.
mon code:
-(void)downloadZip
{
NSLog(@"Start Downloading Zip File");
NSDate *myDate = (NSDate *)[[NSUserDefaults standardUserDefaults] objectForKey:@"LastUpdate"];
NSString *path = [NSString stringWithFormat:phpLinkgetZip, myDate];
NSURL *url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"Checking update at Zip File : %@", path);
NSLog(@"Checking update Time : %@", myDate);
responseData = [[NSMutableData alloc] init];
NSURLRequest* updateRequest = [NSURLRequest requestWithURL: url];
NSURLConnection* connection = [[NSURLConnection alloc] initWithRequest:updateRequest delegate:self];
[connection start];
NSLog(@"Zip Downloading start...");
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[responseData setLength:0];
filesize = [[NSNumber numberWithLong: [response expectedContentLength] ] retain];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[self updateZipDownloaded];
[filesize release];
[connection release];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[responseData appendData:data];
NSNumber* curLength = [NSNumber numberWithLong:[responseData length] ];
float progress = [curLength floatValue]/[filesize floatValue] ;
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"Zip Downloading error");
}
@phl_Austria cela pourrait aider vous-: https://www.objc.io/issues/5-ios7/from-nsurlconnection-to-nsurlsession/ –
Afficher le code de la méthode updateZipDownloaded. – user3182143
Vérifiez ma réponse.Il vous aide. – user3182143