iOS Dropbox SDK on Device fails login with NSURLEr

2020-07-29 01:42发布

问题:

UPDATE: Setting the Dropbox SDK to use HTTP instead of HTTPS cures this problem on an iPhone 3G. I haven't used the SDK on iPhone 4 or iPad yet so I'm not sure of the result.

Playing with the Dropbox SDK on iOS yields these results: in simulator, I can properly link my account using the provided login form class. Changing the build setting to device, I get an error alertView triggered by this method in DBLoginController.m

- (void)restClient:(DBRestClient*)client loginFailedWithError:(NSError*)error {
    [self setWorking:NO];
    NSString* message;
    if ([error.domain isEqual:NSURLErrorDomain]) {
        message = @"There was an error connecting to Dropbox.";
    } else {
        //...

The login form is displayed like so, as referenced in the included sample project:

-(void)settingsPressed {
if (![[DBSession sharedSession] isLinked]) {
        DBLoginController* controller = [[DBLoginController new] autorelease];
        controller.delegate = self;
        [controller presentFromController:self];
    } else {
        [[DBSession sharedSession] unlink];
        [[[[UIAlertView alloc] 
           initWithTitle:@"Account Unlinked!" message:@"Your dropbox account has been unlinked" 
           delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]
          autorelease]
         show];
        [self updateButtons];
    }

}

I'm not sure what to make of this. Apple docs suggest that NSURLErrorDomain is defined as NSURL loading system errors. Can anyone shed light on that?

回答1:

What you should look at is error.code or better [error localizedDescription]

NSURLErrorDomain is a vast error domain :

Constants used by NSError to differentiate between "domains" of error codes, serving as a discriminator for error codes that originate from different subsystems or sources

An error in NSURLErrorDomain could be almost anything, connection down, proxy, certificate errors... Search for NSURLError in that apple documentation page.