2009-10-23 7 views
0

J'ai un code qui fonctionne bien dans les versions 3.0 et 3.1 mais lorsque j'utilise le SDK 3.1.2, le crash de la méthode didReceiveAuthenticationChallenge indique un journal "obj_msgSend". Cela arrive toujours lors de l'utilisation de didReceiveAuthenticationChallenge.La méthode didReceiveAuthenticationChallenge se bloque dans le SDK 3.1.2

J'ai aussi toutes les autres méthodes dans cette classe

réponse didreceive

connectionfinishloading

didfailwitherror etc

S'il vous plaît, aidez-moi

+0

Postez votre code, afin que nous puissions voir ce qui se passe. – Jasarien

+0

code posté comme une réponse à ma question s'il vous plaît jeter un oeil – crystal

Répondre

0

Je posterai la classe de demande de twitter méthode, qui appelle l'URL de l'API XML de twitter pour l'envoi de messages. Qui nécessitent une authentification.

-(void)statuses_update:(NSString *)status delegate:(id)requestDelegate requestSelector:(SEL)requestSelector; { 
    isPost = YES; 
    // Set the delegate and selector 
    self.delegate = requestDelegate; 
    self.callback = requestSelector; 
    // The URL of the Twitter Request we intend to send 
    NSURL *url = [NSURL URLWithString:@"http://twitter.com/statuses/update.xml"]; 
    requestBody = [NSString stringWithFormat:@"status=%@",status]; 
    [self request:url]; 
} 

-(void)request:(NSURL *) url { 
    theRequest = [[NSMutableURLRequest alloc] initWithURL:url]; 

    if(isPost) { 
     NSLog(@"ispost"); 
     [theRequest setHTTPMethod:@"POST"]; 
     [theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 
     [theRequest setHTTPBody:[requestBody dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]]; 
     [theRequest setValue:[NSString stringWithFormat:@"%d",[requestBody length] ] forHTTPHeaderField:@"Content-Length"]; 
    } 

    theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 

    if (theConnection) { 
     // Create the NSMutableData that will hold 
     // the received data 
     // receivedData is declared as a method instance elsewhere 
     receivedData=[[NSMutableData data] retain]; 
    } else { 
     // inform the user that the download could not be made 
    } 
} 

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge: (NSURLAuthenticationChallenge *)challenge { 
    //NSLog(@"challenged %@",[challenge proposedCredential]); 

    if ([challenge previousFailureCount] == 0) { 
     NSURLCredential *newCredential; 
     newCredential=[NSURLCredential credentialWithUser:[self username] password:[self password] persistence:NSURLCredentialPersistenceNone]; 
     [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge]; 

     [newCredential release]; 
    } else { 
     [[challenge sender] cancelAuthenticationChallenge:challenge]; 

     // inform the user that the user name and password 
     // in the preferences are incorrect 
     NSLog(@"Invalid Username or Password"); 
     isFirstTime==NO; 

     UIAlertView * userNameAlert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Invalid credentials. Please check your login details !" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK",nil]; 
     [userNameAlert show]; 

     if(delegate && callback) { 
      if([delegate respondsToSelector:self.callback]) { 
       [delegate performSelector:self.callback withObject:nil]; 
      } else { 
       NSLog(@"No response from delegate"); 
      } 
     } 
    } 
} 


- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { 
    // this method is called when the server has determined that it 
    // has enough information to create the NSURLResponse 

    // it can be called multiple times, for example in the case of a 
    // redirect, so each time we reset the data. 
    // receivedData is declared as a method instance elsewhere 
    [receivedData setLength:0]; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { 
    //NSLog([[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]); 
    // append the new data to the receivedData 
    // receivedData is declared as a method instance elsewhere 
    [receivedData appendData:data]; 
} 

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { 
    // release the connection, and the data object 
    [connection release]; 
    // receivedData is declared as a method instance elsewhere 
    [receivedData release]; 

    [theRequest release]; 


    // inform the user 
    NSLog(@"Connection failed! Error - %@ %@", 

    [error localizedDescription], 
    [[error userInfo] objectForKey:NSErrorFailingURLStringKey]); 

    if(errorCallback) { 
     [delegate performSelector:errorCallback withObject:error]; 
    } 

} 

- (void)connectionDidFinishLoading:(NSURLConnection *)connection { 
    // do something with the data 
    if(delegate && callback) { 
     UIAlertView * userNameAlert = [[UIAlertView alloc]initWithTitle:@"Congratulation" message:@"Your Message is successfully posted to twitter !" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK",nil]; 
     [userNameAlert show]; 

     isLoginChanged =YES; 
     isFirstTime==NO; 

     if([delegate respondsToSelector:self.callback]) { 
      [delegate performSelector:self.callback withObject:receivedData]; 
     } else { 
      NSLog(@"No response from delegate"); 
     } 
    } 

    // release the connection, and the data object 
    [theConnection release]; 
    [receivedData release]; 
    [theRequest release]; 

} 
0

J'ai obtenu la réponse ne libère pas la [nouvelle version de Credential]; dans didreceiveauthentiationchallenge

Questions connexes