0
在iOS下使用GMTAuth來訪問Gmail。測試代碼如下。該帳戶可以通過MailCore訪問,基本上類似的代碼,但用戶/密碼無oAuth。任何線索將不勝感激。GTMAppAuth + MailCore:「無法建立與服務器的穩定連接。」
我得到這個日誌輸出:
__nw_connection_get_connected_socket_block_invoke 3 Connection has no connected handler
2017-02-24 17:20:02.977 Example-iOS[38329:24679819] finished checking account.
2017-02-24 17:20:10.526 Example-iOS[38329:24679819] error loading account: Error Domain=MCOErrorDomain Code=1 "A stable connection to the server could not be established."
,這是代碼:
self.imapSession = [[MCOIMAPSession alloc] init];
self.imapSession.hostname = @"imap.google.com";
self.imapSession.port = 993;
self.imapSession.username = [_authorization userEmail];
GTMAppAuthFetcherAuthorization* authorization =
[GTMAppAuthFetcherAuthorization authorizationFromKeychainForName:kExampleAuthorizerKey];
self.imapSession.OAuth2Token = authorization.authState.lastTokenResponse.accessToken;
self.imapSession.authType = MCOAuthTypeXOAuth2;
self.imapSession.connectionType = MCOConnectionTypeTLS;
GTMAppAuthExampleViewController * __weak weakSelf = self;
self.imapSession.connectionLogger = ^(void * connectionID, MCOConnectionLogType type, NSData * data) {
@synchronized(weakSelf) {
if (type != MCOConnectionLogTypeSentPrivate) {
NSLog(@"event logged:%p %li withData: %@", connectionID, (long)type, [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
}
}
};
// Reset the inbox
self.messages = nil;
NSLog(@"checking account");
self.imapCheckOp = [self.imapSession checkAccountOperation];
[self.imapCheckOp start:^(NSError *error) {
GTMAppAuthExampleViewController *strongSelf = weakSelf;
NSLog(@"finished checking account.");
if (error == nil) {
// TBD: [strongSelf loadLastNMessages:NUMBER_OF_MESSAGES_TO_LOAD];
} else {
NSLog(@"error loading account: %@", error);
}
strongSelf.imapCheckOp = nil;
}];
}