Methode d'erreur pour un NSURL ?

apocaalypsoapocaalypso Membre
09:58 modifié dans API UIKit #1
Bonjour,

dans mon code, je vais chercher le contenu d'un fichier texte sur Internet que j'affiche comme texte dans un UILabel.
Mais je voulais savoir s'il existe une méthode qui permet d'exécuter un code lorsque qu'aucune connexion internet n'est faisable, un peu comme - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error mais pour ce NSURL.

Voici mon code :
// We get the title of the last news from URL<br />	NSURL *titleUrl = [NSURL URLWithString:@&quot;http://www.site.com/title.txt&quot;];<br />	NSString *newsTitle = [NSString stringWithContentsOfURL:titleUrl];<br />		<br />	// Adding the text of the news button from URL content<br />	newsButton.text = newsTitle;<br />


Merci !

Guillaume.

Réponses

  • Philippe49Philippe49 Membre
    09:58 modifié #2
    +(NSString*) stringWithContentsOfURL: encoding: error:
  • apocaalypsoapocaalypso Membre
    09:58 modifié #3
    Oui, j'avais vu cet argument, mais quelle erreur doit-il afficher ?
    Moi il m'affiche le texte de l'Internet alors que j'ai la connexion coupée.
  • Philippe49Philippe49 Membre
    09:58 modifié #4
    Regarde l'exemple URLCache


    Description
    URLCache is a sample iPhone application that demonstrates how to download a resource off the web, store it in the application's data directory, and use the local copy of the resource. URLCache also demonstrates how to implement a couple of caching policies:

    - The local copy of a web resource should remain valid for a period of time (for example, one day) during which the web is not re-checked.

    - The HTTP header's Last-Modified date should be used to determine the last time a web resource changed before re-downloading it.

    The audience for this sample is iPhone developers using resources such as images that are retrieved or updated from the web.
  • Philippe49Philippe49 Membre
    09:58 modifié #5
    Séquence formation :  ;)

    Tu aurais pu trouvé ce lien en lisant par exemple la référence de NSError, de NSURL, ...   
  • apocaalypsoapocaalypso Membre
    09:58 modifié #6
    Désolé, je tacherai d'être plus vigilant la prochaine fois.
    Merci !
Connectez-vous ou Inscrivez-vous pour répondre.