2015-02-01 29 views
7

Geçerli bir URL'im ve desteklenmeyen bir url hatası alıyorum. Bana nedenini söyleyebilir misin?Desteklenmeyen URL iOS

http olduğunu görebileceğiniz gibi: //

// http://fr.radiovaticana.va/news/2015/02/01/le_pape_fran%C3%A7ois_%C3%A0_sarajevo_le_6_juin_prochain/1121065 

Error description=Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo=0x78f97920 {NSUnderlyingError=0x79f78bd0 "unsupported URL", NSLocalizedDescription=unsupported URL} 

Bu şimdiye url init çalışıyordu nasıl:

Yöntem 1:

NSString *[email protected]"http://fr.radiovaticana.va/news/2015/02/01/le_pape_françois_à_sarajevo_le_6_juin_prochain/1121065"; 
NSURL *url=[NSURL URLWithString:path]; 
NSMutableURLRequest * request =[NSMutableURLRequest requestWithURL:url]; 

Yöntem 2:

NSMutableURLRequest * request =[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://fr.radiovaticana.va/news/2015/02/01/le_pape_françois_à_sarajevo_le_6_juin_prochain/1121065"]]; 

cevap

28

URL'ler şunları içermez: ASCII karakter kümesinde olmayan karakterler, böyle karakterlerden kaçınılmalıdır. karakter kümesi URLQueryAllowedCharacterSet

NSString *path = @"http://fr.radiovaticana.va/news/2015/02/01/le_pape_françois_à_sarajevo_le_6_juin_prochain/1121065"; 
NSString *escapedPath = [path stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]; 
NSLog(@"escapedPath: %@", escapedPath); 

Çıkışlı

Kullanım stringByAddingPercentEncodingWithAllowedCharacters:

 
escapedPath: http://fr.radiovaticana.va/news/2015/02/01/le_pape_fran%C3%A7ois_%C3%A0_sarajevo_le_6_juin_prochain/1121065\

Documentation

+1

Çok teşekkür ederim URL Kodlama için karakter grubunu bakın. –

+1

Mükemmel mükemmel cevap :) –

+1

Sweet! Güzel cevap –