How do I set Basecamp credentials using apple IOS for iPad

坚强是说给别人听的谎言 提交于 2019-12-06 15:22:01

As is always the way, I worked it out eventually. Once I started using the didReceiveAuthenticationChallenge method things started to fall into place.

So. I simplified my request method:

- (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];

    }

and then set up a method for receiving the authentication challenge:

- (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];

}

then set up a didReceiveData method to catch the data returned:

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    NSLog(@"Did receive data"); 

    NSString * strResult = [[NSString alloc] initWithData: data encoding:NSUTF8StringEncoding];
    NSLog(strResult);
}

Hope this helps someone else out there.

Still happy to hear better method for this

JJ

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!