For iOS 6.[something] onwards Cookies, SQLite data and localStorage data for Full Screen Web Apps is stored separately from the Safari data. I have a token that I need persisted to the Home-Screen app when saving to Home-Screen.
There is a cookie tester here. And a discussion here.
Has anyone found an elegant solution to this problem? Very ugly solutions will also be considered:)
Clear the local storage in Safari (Max OSX) To clear the local storage in Safari, do the following: From the Power BI service page, click the Develop menu and choose Web Inspector. On the Console tab, type localStorage. clear() in the field and press Enter.
Open the Safari app on your iPhone and go to a website you visit frequently. Tap the Bookmark icon and then tap Add to Home Screen. Accept the suggested name or enter a different name. Tap Add to save the shortcut to the iPhone Home screen. This article explains how to make a Safari shortcut and add it to the iPhone home screen.
Launch Safari and navigate to a website you frequently visit. Tap the Bookmark icon at the bottom of the screen (it resembles a box with an upward-pointing arrow). Tap Add to Home Screen. Accept the suggested name for the shortcut, or enter one you like better.
Make sure the Safari tools are visible, so either scroll up on the webpage or tap the top bar to make them appear if they're not already. Next, tap the share button at the bottom (or top if you're in landscape mode). Look at the bottom row of activities in the share sheet, then swipe left until you see "Add to Home Screen," and tap on it.
This is most important for websites you visit frequently that have no dedicated iOS app. To begin, launch Safari and load up any webpage you want to save. Make sure the Safari tools are visible, so either scroll up on the webpage or tap the top bar to make them appear if they're not already.
Since iOS 5 Apple have been making Home Screen bookmarks more and more isolated in terms of sharing data between the Safari browser and what is now considered a sandbox application.
At the time of writing (iOS 7.1 in beta), you have only one option.
When your page loads, add your token/data to a query string parameter in the URL using JavaScript (window.location.search
). When the user saves the site to their Home Screen, the URL is used as the key. Your JavaScript can easily extract the query string parameter you sneaked in earlier if you detect that you are in Home Screen mode (window.standalone
). This should work forever, except the value in the URL will also be there forever.
Another trick that is to 'render' any value you want to carry across to the Home Screen in the DOM. Since the early versions of iOS, the HTML that is rendered at the time it is saved to Home Screen, will remain unchanged. When launching a Home Screen web app, it does not request the content from the URL. It simply loads the HTML that was previously saved with no initial web request (all links to CSS and JS in the HTML will be requested, but not the page itself). With the knowledge that the HTML is forever saved, so will anything you rendered in it as well. The only way to update your page is to do a windows.reload
or equivalent redirect if you aren't pulling your content via AJAX. Long story short, inject your value into a hidden input field for example and it will be transferred across.
Option #1 is will probably last forever, it's not likely the Home Screen will ever alter the URL in any way. Just make sure you have some JS in place to flip a switch and reload the page if you ever want to get rid of it.
Option #2 is somewhat risky because one day the all knowing Apple could decide that a initial page request should actually be made instead of using the same HTML at the point it was saved. This would then wipe out the data you have and the current state of any elements in the DOM.
UPDATE: The DOM injection technique is no longer valid either (iOS 7+), only the DOM directly downloaded from the server is saved to Home Screen. Any dynamic changes made during runtime are lost. Struck out option #2 since the question is for iOS 7 and it longer works, which leaves you with only option #1, adding something to the URL which will always get saved to Home Screen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With