Search code examples
ionic-frameworkwebkitibm-mobilefirsthybrid-mobile-app

Where do I write code to clear cookies in Hybrid iOS App


I have a hybrid app which uses Ionic and IBM's Mobilefirst platform. During login we get a cookie from the authentication service. I have to remove this cookie on logout or next time the user can log in even with incorrect credentials.

So during logout I call WL.Client.reloadApp() before going back to login screen. This clears the cookies and then login works correctly in Android and browsers. But in iOS cookies aren't cleared on reload and having searched I came across a solution to clear cookies using native code.

But my confusion is where do I add this native code? There are a few initialization methods in my application's default .m file. I have tried adding the code to clear cookies in -(void)wlInitDidCompleteSuccessfully. But this block doesn't seem to be executed on reloading.

Any suggestion on what I should try to fix this problem.


Solution

  • Two options:

    1. Use the WL.Client.deleteCookie(name) API to clear the cookie.
    2. Write a simple Cordova plugin (https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/7.1/adding-native-functionality/) to clear the cookies or google for 'cordova clear cookies' to find such plugins in the market.