如何使用Apple IOS for iPad设置Basecamp凭证
我试图要求我公司的Basecamp信息为我们正在build立的内部项目。 我知道如何在ASP.NET环境中添加凭证,但是我是iPad开发新手,似乎无法从Basecamp获得适当的响应。 这是我正在做的事情:
NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://mybasecampname.basecamphq.com/projects.xml"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0 ];
我添加了Bsaecamp需要的HTTP标头,如下所示:
[theRequest setValue:@"application/xml" forHTTPHeaderField:@"Content-Type" ]; [theRequest setValue:@"application/xml" forHTTPHeaderField:@"Accept" ];
我知道我也需要发送我的凭据进行身份validation – 我的身份validation令牌和任何我喜欢的密码,但我不确定最好的方法来做到这一点。 这就是我想要的:
NSURLCredential *credential = [NSURLCredential credentialWithUser:@"MY TOKEN HERE" password:@"x" persistence:NSURLCredentialPersistenceForSession];
我的问题是:我在这里正确的轨道上,还是我完全错过了一些东西?
下面是Basecamp API详细信息的链接,它解释了它需要的内容: http : //developer.37signals.com/basecamp/
帮助赞赏。
乔
总是这样,我终于搞定了。 一旦我开始使用didReceiveAuthenticationChallenge方法,事情就开始落实了。
所以。 我简化了我的请求方法:
- (void)startRequest { NSURL *url = [NSURL URLWithString:@"http://mybasecampproject.basecamphq.com/projects.xml"]; NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url]; // Start the connection request urlConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self]; }
然后build立一个接收authentication挑战的方法:
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge { NSLog(@"Authentication challenge..."); NSURLCredential *cred = [[[NSURLCredential alloc] initWithUser:@"my basecamp token here" password:@"X" persistence:NSURLCredentialPersistenceForSession] autorelease]; [[challenge sender] useCredential:cred forAuthenticationChallenge:challenge]; }
然后设置一个didReceiveData方法来捕获返回的数据:
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { NSLog(@"Did receive data"); NSString * strResult = [[NSString alloc] initWithData: data encoding:NSUTF8StringEncoding]; NSLog(strResult); }
希望这可以帮助别人。
很高兴听到更好的方法
JJ
- 自定义schemeURI不适用于“networking”客户types – 带有Firebase的Google
- 使用用户名而不是电子邮件进入ios应用程序和firebase
- 需要Firebase重新validation
- 如何让Rails告诉用户login的移动应用程序?
- 转换为Swift 3(Swift和Firebase项目)
- 为iOS创build一个用户authentication系统(以前用Parse希望AWS)
- 未经身份validation的用户在AWS Cognito上authentication用户
- 将AFIncrementalStore与Auth令牌一起使用
- 阻止使用标签栏控制器(storyboard)访问UIViewControllers