google oauth - GTMAppAuth + MailCore: "A stable connection to the server could not be established." -


under ios using gmtauth access gmail. test code follows below. account accessible mailcore, similar code, user/pw no oauth. clues appreciated.

i log output:

__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 server not established." 

and code:

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

update: figured out solution. here's full working code:

func loadaccount() {     // model file holding account details...     let account = emailaccounts[currentaccount]      imapsession = mcoimapsession()     imapsession?.hostname = account.hostname     imapsession?.port = 993     imapsession?.username = account.username     imapsession?.authtype = .xoauth2      // email helper code guide:     // https://github.com/mailcore/mailcore2/wiki/implementing-oauth-2.0     imapsession?.oauth2token = emailhelper.singleton().authorization?.authstate.lasttokenresponse?.accesstoken      // important (wasn't working other values)     imapsession?.connectiontype = .tls      imapsession?.connectionlogger = { [unowned self] (connectionid, type, data) in         let lockqueue = dispatchqueue(label: "com.inboxzero.lockqueue")         lockqueue.sync() {             if (type != mcoconnectionlogtype(rawvalue: nsinteger(2))) { // mcoconnectionlogtypesentprivate                 if let thedata = data, let str = connectionid {                      let thestring = string(describing: thedata)                     print("event logged:\(str) \(type) withdata: \(thestring)")                 }             }         }     }      // reset inbox:     messages = nil     isloading = false     print("checking account \(self.imapsession!.username!)")     imapcheckop = self.imapsession?.checkaccountoperation()     if let checkop = imapcheckop {         checkop.start( { (error) in             print("finished checking \(self.imapsession!.username!)")             if (error == nil) {                 self.loadlastnmessages(nmessages: self.number_of_messages_to_load)             }             else {                 print("error loading account \(self.imapsession!.username!): %@", error!)                 self.alertwithtitle(title:"mail core", message:error.debugdescription)                 return             }         })     } } 

Comments