20.04.2013 Views

Tutorial pratici per iPhone SDK v1.6 - Get a Free Blog

Tutorial pratici per iPhone SDK v1.6 - Get a Free Blog

Tutorial pratici per iPhone SDK v1.6 - Get a Free Blog

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Nota: se invece di leggere la vostra timeline vorreste leggere i messaggi di un utente (non la<br />

sua timeline, solo i suoi tweet) dovete sostituire l’istruzione alla riga 19 con la seguente:<br />

1 [twitterEngine getUserTimelineFor:username sinceID:nil<br />

startingAtPage:0 count:5];<br />

Inseriamo, ora, dei metodi obbligatori da inserire, in quanto parte del delegato “MGTwitterEngineDelegate”.<br />

Eccoli:<br />

1<br />

2<br />

3<br />

4<br />

5<br />

6<br />

7<br />

8<br />

9<br />

10<br />

11<br />

12<br />

13<br />

14<br />

15<br />

16<br />

17<br />

18<br />

19<br />

20<br />

21<br />

22<br />

23<br />

24<br />

- (void)requestSucceeded:(NSString *)requestIdentifier{<br />

NSLog(@"Request succeeded (%@)", requestIdentifier);<br />

}<br />

- (void)requestFailed:(NSString *)requestIdentifier<br />

withError:(NSError *)error{<br />

NSLog(@"Twitter request failed! (%@) Error: %@ (%@)", requestIdentifier,<br />

[error localizedDescription],<br />

[[error userInfo] objectForKey:NSErrorFailingURLStringKey]);<br />

! [spinner stopAnimating];<br />

! UIAlertView *alert = [[UIAlertView alloc]<br />

initWithTitle:@"Errore!"<br />

message:@"Connessione non riuscita.\nControlla i dati d'accesso"<br />

delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];<br />

! [alert show];<br />

! [alert release];<br />

}<br />

- (void)directMessagesReceived:(NSArray *)messages<br />

forRequest:(NSString *)identifier{<br />

NSLog(@"Got direct messages:\r%@", messages);<br />

}<br />

- (void)userInfoReceived:(NSArray *)userInfo forRequest:(NSString<br />

*)identifier{<br />

NSLog(@"Got user info:\r%@", userInfo);<br />

}<br />

- (void)miscInfoReceived:(NSArray *)miscInfo forRequest:(NSString<br />

*)identifier{<br />

! NSLog(@"Got misc info:\r%@", miscInfo);<br />

}<br />

L’unico metodo a cui ho aggiunto un po’ di codice è il secondo, ovvero “requestFailed: withError:”.<br />

Questo è richiamato se la connessione con Twitter non è possibile, quindi avviamo una<br />

UIAlertView che lo comunica all’utente e fermiamo la rotella. Come messaggio comunichiamo<br />

che i dati d’accesso sono errati, in realtà dovremmo controllare il codice d’errore e inserire un<br />

messaggio a seconda dell’errore riscontrato (potrebbe non essere presente la connessione, oppure<br />

Twitter potrebbe essere down, o i dati inseriti potrebbero essere errati, etc).<br />

<strong>Tutorial</strong> <strong>pratici</strong> <strong>per</strong> <strong>iPhone</strong> <strong>SDK</strong>! 141

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!