Freejack » NSURL http://www.freejack.fr Gestion de Projet et Développement Multimédia Fri, 26 Nov 2010 11:52:55 +0000 en hourly 1 http://wordpress.org/?v=3.0.3 URLWithString retourne nil http://www.freejack.fr/urlwithstring-retourne-nil http://www.freejack.fr/urlwithstring-retourne-nil#comments Fri, 19 Nov 2010 19:51:29 +0000 Freejack http://www.freejack.fr/?p=903 En cherchant à créer un NSURL à partir d’un fichier local, j’ai utilisé la méthode URLWithString de NSURL comme ceci :

NSURL *baseURL = [NSURL URLWithString:url];

URLWithString retournait nil… Le problème venait du chemin local qui contenait un espace, ce chemin était du type :

/Library/Application Support/iPhone Simulator/4.0.2/Applications/516C..

L’espace entre iPhone et Simulator n’était pas apprécié par URLWithString. Pour contourner le problème, il suffit de supprimer du chemin tous les caractères non-ASCII :

NSURL *baseURL = [NSURL URLWithString:[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

Source : http://stackoverflow.com/questions/1981390/urlwithstring-returns-nil

]]>
http://www.freejack.fr/urlwithstring-retourne-nil/feed 0