0

I am working on an iOS app that is almost completely native.

However, there is one part of the app that simply has to be a web view.

What I need to do is have a user select items that are added to a cart stored in a session on an AngularJS website. After they select the items, they just open a web view with the checkout page that already knows what items have been selected from within the app.

How is one to do this?

Thanks

Simon Narang
  • 69
  • 1
  • 1
  • 6

1 Answers1

1

My suggestion is to use local storage over session and cookies as session is different for every tab in the browser and cookies are have sessions(time to get deleted). Local storage values stay there until someone delete them. For simplicity, we use plain javascript code to access local storage in angularjs.

Coming to your question, on user login store user id, and password in local storage of the browser.

For example, we can call like this directly in a angularjs controller

localStorage.setItem(key, value) // to store a value

localStorage.setItem(key, JSON.stringify(value)) // to store an object

localStorage.getItem(key) // to retrieve value

JSON.parse(localStorage.getItem(key)) // to retrieve an object

examples as per your requirement,

localStorage.setItem('userId', userId)

var user = localStorage.getItem('userId')

if(user){ //if user already logged in
  // retrieve user relevant data from DB, show home page directly or whatever you want. 
}

I think there will be security risk if you store selected items in local storage. But if you want to store them as well, just store them on selecting confirmation.

localStorage.setItem('selectedItems', JSON.stringify(selectedItems)) I assumed selectedItems as an object. Retrieve them based on your requirement.

Mr_Perfect
  • 8,254
  • 11
  • 35
  • 62