swift - Error while getting Uber AccessToken in ios -
i trying accesstoken uberrides. followed uber developer portal tutorial. i'm not getting accesstoken loginmanager
class while login. here code.
@ibaction func getride(sender: uibutton) { let loginmanager = loginmanager() loginmanager.login(requestedscopes:[.ridewidgets], presentingviewcontroller: self, completion: { accesstoken, error in // completion block. if accesstoken non-nil, you’re go print("::accesstoken::") print(accesstoken) print("::error::") print(error) }) }
but i'm getting following log while clicking on custom button.
::accesstoken::
nil
::error::
optional(error domain=com.uber.rides-ios-sdk.ridesauthenticationerror code=20 "a network error occured." userinfo={nslocalizeddescription=a network error occured.})
i checked , internet connection working properly. still error occurring.
please me solve this.
also set callback uri uber developer dashboard
set start , end location params
let pickuplocation = userlocation let dropofflocation = tolocation let params = rideparametersbuilder().setpickuplocation(pickuplocation).setdropofflocation(dropofflocation).build() let loginmanager = loginmanager() if tokenmanager.fetchtoken() != nil { self.riderequestviewcontroller = riderequestviewcontroller(rideparameters: params, loginmanager: loginmanager) self.riderequestviewcontroller.delegate = self self.riderequestviewcontroller.view.frame = cgrectmake(0, 50, self.view.frame.size.width, self.view.frame.size.height - 50) self.view.addsubview(self.riderequestviewcontroller.view) self.addchildviewcontroller(self.riderequestviewcontroller) self.riderequestviewcontroller.didmovetoparentviewcontroller(self) } else { loginmanager.login(requestedscopes: [.ridewidgets], presentingviewcontroller: self) { (accesstoken, error) in if error == nil { print(accesstoken) dispatch_async(dispatch_get_main_queue(), { tokenmanager.savetoken(accesstoken!) self.riderequestviewcontroller = riderequestviewcontroller(rideparameters: params, loginmanager:loginmanager) self.riderequestviewcontroller.delegate = self self.riderequestviewcontroller.view.frame = cgrectmake(0, 50, self.view.frame.size.width, self.view.frame.size.height - 50) self.view.addsubview(self.riderequestviewcontroller.view) self.addchildviewcontroller(self.riderequestviewcontroller) self.riderequestviewcontroller.didmovetoparentviewcontroller(self) }) } else { dispatch_async(dispatch_get_main_queue(), { let alert = uialertcontroller(title: "error", message: error?.localizeddescription, preferredstyle:.alert) let action = uialertaction(title: "ok", style: .cancel, handler: nil) alert.addaction(action) self.presentviewcontroller(alert, animated: true, completion: nil) }) } } }
set riderequestviewcontroller delegate , check if access token missing check callback uri in uber deshboard
extension uberrideviewcontroller : riderequestviewcontrollerdelegate { func riderequestviewcontroller(riderequestviewcontroller: riderequestviewcontroller, didreceiveerror error: nserror) { let errortype = riderequestviewerrortype(rawvalue: error.code) ?? .unknown switch errortype { case .accesstokenmissing: print("access missing") // no accesstoken saved case .accesstokenexpired: print("expired") // accesstoken expired / invalid case .networkerror: print("network error") // network connectivity error case .unknown: print("error") default: print("default") } } }
Comments
Post a Comment