我想在我的应用程序中使Twitter工作,一切正常,但代码似乎无法识别来自Twitter的错误。如果用户名/密码无效,我通过这个功能得到一条错误消息:http验证在Xcode
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSString* strData = [[[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSASCIIStringEncoding] autorelease];
NSLog(@"Received data: %@", strData) ;
return ;
}
它打印:接收到的数据: 无法验证您的身份。 。
但是,应用程序继续发布我的推文视图并忽略错误。很明显,我没有设置正确的东西来检测这样的错误,所以我的问题是如何让Xcode识别这样的错误?这使用基本的HTTP身份验证btw,并没有提及有关OAuth的任何内容......只是试图让这个工作。
-(void) onLogin:(id)sender
{
[loading1 startAnimating];
NSString *postURL = @"http://twitter.com/account/verify_credentials.xml";
NSMutableURLRequest *request = [ [ NSMutableURLRequest alloc ] initWithURL: [ NSURL URLWithString:postURL ] ];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
if (!theConnection)
{
UIAlertView* aler = [[UIAlertView alloc] initWithTitle:@"Network Error" message:@"Failed to Connect to twitter" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
[aler show];
[aler release];
}
else
{
receivedData = [[NSMutableData data] retain];
}
[request release];
}
-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
if ([challenge previousFailureCount] == 0 && ![challenge proposedCredential])
{
NSURLCredential *newCredential;
newCredential=[NSURLCredential credentialWithUser:txtUsername.text
password:txtPassword.text
persistence:NSURLCredentialPersistenceNone];
[[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];
}
else
{
isAuthFailed = YES;
[[challenge sender] cancelAuthenticationChallenge:challenge];
}
}
我知道旁边没有关于互联网的东西,所以请尽量帮我在这里 – fraggleRockz 2010-05-04 14:14:57
这有什么好做的Xcode - Xcode的只是一个IDE - 你可能意味着Objective-C和CocoaTouch。 – 2010-05-04 15:24:50