Runkeeper Entrance

I use runkeeper in my application to associate it with data and get data from them. When I click the button, it directs me to the browser, where I enter the runkeeper web application, hit the service after receiving the access token and user_Id, and return back to my application. Now again, if I click on a button in my application to connect, it directly asks me to redirect back to my application, but I want it to ask for a login every time I click to connect. I know that I need to clear my cache and cookies, but I don’t know how to do this.

@IBAction func btnRunKeeperClicked(sender: AnyObject) { MSYRunKeeper.shareInstance.loginWithRunKeeper { (result, success) in print(result) if success{ print(result) let accessToken = result["accessToken"] as? String ?? "" self.hitServiceToGetDataFromRunkeeper(accessToken) }else{ print("error...") } } } 

func hitServiceToGetDataFromRunkeeper (accessToken: String) {

  showActivityIndicator(true, inViewConroller: self, animated: true) let dict = HelperClass.userDefaultForAny("User_Detail") var userID = "" var serviceKey = "" if(dict != nil){ userID = (dict!["userID"] as? String)! serviceKey = (dict!["service_key"] as? String)! } var paramDictionary = NSMutableDictionary() paramDictionary = ["method":"runkeeperLogin","service_key":serviceKey,"userID":userID,"runkeeperAccessToken":accessToken,"isRunkeeperConnect":"1"] print_debug(paramDictionary) FSServicesClass.sharedInstance.postWithParamater(paramDictionary, sBlock: { (result) in if(NSDictionary(dictionary: result).valueForKey("success")?.integerValue == 1){ showActivityIndicator(false, inViewConroller: self, animated: true) self.btnRunKeeperConnected.setTitle("Connected", forState: .Normal) if self.btnFitBitConnected.titleLabel?.text == "Connected"{ self.btnFitBitConnected.setTitle("Disconnected", forState: .Normal) } print(result) let dict = HelperClass.userDefaultForAny("User_Detail") HelperClass.removeFromUserDefaultForKey("User_Detail") let dict2 = updateUserDetailForConnetectdAppsAndDevices(dict!, isfitbitConnected: "0", isRunkeeperConnected: "1") HelperClass.saveToUserDefault(dict2, key: "User_Detail") popAlertMessageController(self, title: "Alert", message: NSDictionary(dictionary: result).valueForKey("errstr") as? String ?? "") }else{ showActivityIndicator(false, inViewConroller: self, animated: true) popAlertMessageController(self, title: "Alert", message: NSDictionary(dictionary: result).valueForKey("errstr") as? String ?? "") } }, fBlock: {(ErrorResult) in showActivityIndicator(false, inViewConroller: self, animated: true) popAlertMessageController(self, title: "Please try again", message: NSDictionary(dictionary: ErrorResult).valueForKey("errstr") as? String ?? "") //print(ErrorResult) }) } 
+6
source share
2 answers

You can delete cookies from the UIWebView runkeeper as follows

 let storage = NSHTTPCookieStorage.sharedHTTPCookieStorage() for cookie: NSHTTPCookie in storage.cookies! { storage.deleteCookie(cookie) } NSUserDefaults.standardUserDefaults().synchronize() 

OR

 let cookieJar : NSHTTPCookieStorage = NSHTTPCookieStorage.sharedHTTPCookieStorage() for cookie in cookieJar.cookies! as [NSHTTPCookie]{ NSLog("cookie.domain = %@", cookie.domain) if cookie.domain == "www.Your runkeeper url.com" || cookie.domain == "api.Your runkeeper api .com"{ cookieJar.deleteCookie(cookie) } } 

also remove the runkeeper token from the default user.

0
source

Authorize user First you try to connect to RunKeeper. If the user has previously allowed the application and the access token is still available, the connection will occur immediately and without any intervention:

  [[AppData sharedAppData].runKeeper tryToConnect:self]; 

If the user did not provide authorization, or the access token was lost / deleted, you will need a delegation method. Authentication will be triggered. In this method, you can request authorization through OAuth.

  - (void)needsAuthentication { [[AppData sharedAppData].runKeeper tryToAuthorize]; } 

To log in using OAuth as soon as the login is successful, it will save tokens and credits, so you need to manually clear the keyfain prefrences. To perform this check below:

Delete Accounts

To delete an account and its tokens from the store:

 [[NXOAuth2AccountStore sharedStore] removeAccount:account]; 

Please note: if you used UIWebView to request access to the service as described above, it is likely that the token was cached in [NSHTTPCookieStorage sharedHTTPCookieStorage]

You can remove the authentication token from the cookie cache using:

 for(NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) { if([[cookie domain] isEqualToString:@"myapp.com"]) { [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie]; } } [[NSUserDefaults standardUserDefaults] synchronize]; 

Where myapp.com is the domain from which you received the auth token, likille url authorization assigned to the repository at the time of the request. For convenience, you might want to save the token domain in account.userData so that it is easily accessible if you need to delete cookies.

0
source

Source: https://habr.com/ru/post/1012611/


All Articles