Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to to share context between Safari and Native App?

Tags:

html

ios

native

I have a need to set some context via Safari (a context token), and then read that context from a native iOS app. What are the best practices for doing this?

A couple thoughts so far:

  1. Set the context in an HTML 5 database, but I'm not sure this will work because the database might be only accessible from Safari. Would using a WebUIView in the native app allow me to access the same HTML5 database / local storage as Safari?
  2. Set the context in device storage, but I'm not sure this will work because I don't know if Safari can actually write to device storage.
like image 352
Paul Fryer Avatar asked Aug 01 '12 16:08

Paul Fryer


1 Answers

I would suggest one of these two options:

  • Let the web server keep track on the user both in the app and on the website, for example by creating a user account.

or

  • Pass the context token to the app immediately via an URL-scheme by registering your app as a protocol handler, see more info here

    Suggested way:

    1. Send e-mail with link and context token, when user clicks link, save context token in cookie in safari, then redirect to appstore for app download.
    2. When the user downloaded the app and opens it, present a button for the user, when the user clicks it, open a web page in safari.
    3. Safari loads the cookie with the context token, and then triggers another link using a URL-scheme like yourAppName://contextToken=12345678. The link opens your app which reads the context token from the URL.

There is no best practice for directly sharing data between safari and a native app directly and that it is simply not intended that you should do that. All cookies and storages are sandboxed for each app and safari has its own sandbox.

Letting your server doing the job via user accounts is the best and clean way i.m.o. That is why you have user accounts. If you didn't try out the protocol handler for reading specific URLs, that could also be made handy I think.

like image 179
jake_hetfield Avatar answered Oct 12 '22 23:10

jake_hetfield