Windows Phone 8.1 localStorage issue - windows-phone-8.1

I'm interesting if someone have experience loading local html file in windows Phone 8.1 WebBrowser control? It looks like WP treat local files as they don't belong to the same server, so it creates localStorage object for each file separately.
So if you create two WebBrowser controls in your app and load two html files in each of them, they don't see each other data. But if you close app and load it again, each remembered it's own data.
I know that WP 7.1 do not have localStorage, but WP 8.1 do, and I'm wondering why this not work like in Android or iOS.
Do you know any workaround?

I faced the same issue and it turned out that localStorage is stored separately when navigating via a different protocol. I solved this by referring to HTML source with 'x-wmapp0:' as prefix. This requires you to provide an absolute URI.
new System.Uri("x-wmapp0:/www/index.html", UriKind.Absolute);

Related

Titanium Windows Phone: How can i save a file in visible folders?

I'm developing a windows phone application built with Titanium SDK 5.2.2.
I'm not able to save a file in directories directly accessible by the device (like Downloads directory).
I tried to use the only supported functionalities of Titanium API Titanium.Filesystem.getFile and Titanium.Filesystem.File.write, but the only way to save the file is to use Ti.FileSystem.applicationDataDirectory or Ti.File.resourcesDirectory to decide the path where store it.
It seems that, using these API, I cannot store file in one of the directories visible by the device(Documents, Downloads, Photos, Music), and then make them available inside the device.
Can I perform this download in the path visible to the device such as Downloads folder?
You might be able to use the externalStorageDirectory location:
https://github.com/appcelerator/titanium_mobile_windows/blob/e3ecddfe13179509e3b8d0699141763262ef5a97/Source/Filesystem/src/Filesystem.cpp#L81
We've had a similar request to expose the Downloads/Documents folder for iOS. I'd suggest to add a comment to request parity for Windows or create a new ticket:
https://jira.appcelerator.org/browse/TIMOB-23197
I opened an issue on Appcelerator JIRA for this question:
https://jira.appcelerator.org/browse/AC-3615 .

PhoneGap store HTML Files on Device

I have to build an App for Windows Mobile and iOS. So I decided to create this with PhoneGap.
The app should only display HTML-Files.
These files are stored on a server and can change every day.
So I created already an API which delivers the files.
My solution would be:
In my PhoneGap-App I use AJAX to get the files (this is no problem and should already work...).
To the question:
How can I store the files on the device? Is this possible with PhoneGap?
The app have to work offline too (because of this I need to store the files)...
And if this is possible: It should sync only the differences (between device/app and server) --> keyword rsync??
Thank you for your help!
Emanuel :)
Have you checked here?
You can definitely store files locally on android platform.(I have already done that). However, I haven't done it on IOS.
So please investigate, if features I gave the link above, available for safari (IOS).
Synching only diff should be implemented on the server side and should be responsibility of your API.
Yes you can store files locally.
I would recommend the Phonegap File Transfer plugin for downloading files. It supports iOS and Windows phone 7 and 8 and can download and save the file locally. At the Cordova file plugin github you can see the paths where you can save the files for iOS, I haven't found a table for windows phone yet.
But I would not recommend you download the HTML files since they can be very big. You should dynamically create the mobile pages you need, since you would only need to download the displayed text and attributes for some HTML-tags.
The way you can do this is by having a server back-end where you can change the content of the pages. The plain HTML should then be saved in a database with a creation and modification timestamp(needed to check if you have the latest updates). You would then pull the data out of the database with your PHP and echo it as a JSON. Your app just has to make a AJAX-GET request to the server and save the data locally in a database. I would recommend the Cordova SQLite Storage plugin for the local database. Whenever a page is opened you should dynamically create a mobile page.
This way your app doesn't request huge amount of data from a server, which can be more appealing to your app users.

OneDrive not available in FilePicker

I am playing alittle with windows phone 8.1 app creating. Using C# and phone emulator in VS2013. I have read on microsoft's page that i should be able to see OneDrive in standard file picker (msdn.microsoft.com/en-US/en-en/library/windows/apps/dn263258.aspx):
Use the built-in Windows features.
Whenever possible, use the Windows features and UI to host or interact
with OneDrive. For instance, use the file picker provided by the
Windows.Storage.Pickers namespace for opening and saving files. As
another example, have your app use the Windows application data APIs
to save smaller pieces of data across a user's devices.
I am using standard code from tutorial like:
openPicker.FileTypeFilter.Add("*");
StorageFile file = await openPicker.PickSingleFileAsync();
and it works but there is no OneDrive to choose. I have internet connection on emulated device and i am logged in to OneDrive.
Have you integrated your file picker with the OneDrive contract?: http://msdn.microsoft.com/en-us/library/windows/apps/hh465192.aspx
You can also use the Live SDK single sign-on feature for Windows Phone here: http://msdn.microsoft.com/en-us/library/dn631823.aspx This way, your app should work for your testing purposes because you are already signed in.
I hope this helps!

Where can I find files saved in ApplicationData.Current.LocalFolder while developing a Windows Phone 8.1 app?

To my understanding, WinRT apps store their application data in
C:\Users\{user}\AppData\Local\Packages
My Windows Phone 8.1 application seems to have its own folder there as well, with an odd name like
App.aba911777.a60e8.a46c0.aa90d.a5038d92d276e_8wekyb3d8bbwe
However, when I browse the directory, I cannot find any of the files I've saved to ApplicationData.Current.LocalFolder. They are definitely there, because if I re-run my app in the emulator (which hasn't been closed at all), can find the cached files. Presumably these files are saved somewhere on my actual hard drive; where would they be?
(LocalFolder.Path gives me C:\Data\Users\DefApps\APPDATA\Local\Packages\2cdc8aaf-b7fe-4bcb-992a-18ad6f140771_b83k3kj2dpxdw\LocalState but I'm not sure how to find that on my hard drive)
To transfer/access files on Windows Phone Emulator (also works with device) you can use:
Isolated Storage Explorer tool - here is a good link how to do it, and also one useful here.
a very nice tool is Isolated Storage Spy - which now supports also WP8.1
Windows Phone Power Tools from here - you will have to check if that already works with WP8.1.
Search your SQLite db file in "C:\Users\\AppData\Local\Packages\".
localFolder.Path gives you correct location. You are not able to find that folder because AppData is been hidden. Please change your PC settings to view this folder.
Thanks

Is there a way to persist cookies or HTML5 localStorage across WebBrowser instances on Windows Phone?

Short version: I have a WebBrowser control hosted in a Windows Phone 8 app. How can I store values from javascript so that they persist across the user closing and reopening my app?
Long version:
I'm developing a Windows Phone 8 application that has a single WebBrowser control hosted in a single MainPage.xaml page that lives for the entire life of my app. I created the app with the "Windows Phone HTML5 App" project type when creating the project in Visual Studio 2012. 99% of my application is hosted in web pages (on the internet, not stored on the phone) that I direct the WebBrowser to go to when the app starts up. In my application's web pages I'm trying to persist data across pages and across sessions. For example, once the user logs in once then I want to store that on the phone so the next time they start the app they don't have to log in again.
Cookies and HTML5 Local Storage (via window.localStorage.setItem and getItem) both work fine for sharing data across pages in the app while the app is running and even if you switch out of the app (via the Windows phone "hard button") and go back in. But if the user exits the app by pressing the hard "back" button then the next time the app is started all localStorage and cookies seem to be gone.
Is this the expected behavior? I guess I'm not sure where WebBrowser would store the data (Isolated Storage? Or maybe in the same place it's stored if going to the web site with Internet Explorer?). In any case, if there's no "fix" for this, can anyone the best way for me to provide my own storage mechanism so that I can let my javascript code persist values across instances of my app running? I'm happy to use the app's Isolated Storage if only I knew of a way to get and retrieve values from it using javascript. Thank you.
I'm not sure if this is expected behaviour or not.
To get at the Isolated Storage you will need to use JS/.NET interop.
if you want to trigger the persistent storage from JS:
Use window.external.notify in JS, generating a JSON string (for instance) to pass along to the .NET side. That could be written to IsolatedStorage without the .NET having to parse the data. You could use IsolatedStorage.AppSettings or a full file depending on the size of the data.
Alternately you could trigger the process from .NET:
Call WebBrowser.InvokeScript to call a JS function which returns the same JSON string representing your data.
The .NET side could detect and restore this data on startup and use WebBrowser.InvokeScript to pass the JSON string back into the WebBrowser via a JS function.
You'd of course have to deal with error cases (attempting to restore bad/corrupt JSON).
Also, if you trigger this from .NET in response to the App.Closing event you need to watch out that you don't take too long writing data.
The faster you run the better, but this definitely needs to be done within 10 seconds or the OS will kill your app.
See MSDN docs for WebBrowser.InvokeScript() and ScriptNotify registration to window.external.notify.