IOS Localstorage not working - ios

We are working on an IOS app that has been developed in swift.
This consists of a webview where in the initial pages are native and then we are moving to webview.
During the transition from the native pages to the webview we need to store some values in the LocalStorage so those can be used in the webview.
This is working in Android but we are facing some problems in IOS. The Android code is as follows:-
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT)
wv_content.evaluateJavascript("localStorage.setItem('" + key + "','" + value + "');", null);
else
wv_content.loadUrl("javascript:localStorage.setItem('" + key + "','" + value + "');");
https://developer.apple.com/icloud/documentation/data-storage/index.html
https://forums.cocoon.io/t/system-save-load-and-local-storage-do-not-work-after-compile-with-cocoon-io-to-ios-webview-mode/3319/49
PhoneGap iOS 7 and localStorage
But none of them has been successful for me. I have googled around and there were no perfect code samples that could have been used to display the way it can be done.
Please help me with a code sample of doing the same with enabling the needed preferences.
Thanks for help.
UPDATE
Below is the IOS code I am using and this way is not working for me.
web_browser.delegate = self
let javaScript = "localStorage.setItem(\"user\", \"\(jsonString!)\")"
web_browser.stringByEvaluatingJavaScript(from: javaScript)
web_browser.loadRequest(URLRequest(url: url!))

Related

Nativescript with Googlemap static api - issue on iOS

I am trying to add an image of a map generated by the google map static api in my Nativescript application (I'm using Nativescript with Vue).
I am able to make it work on Android but I have some issues on iOS.
I simply have an Image component like that <Image :src="map_source" />
And in my vue data, I have map_source: "https://maps.googleapis.com/maps/api/staticmap?&markers=48.2,2.1&path=color:red|weight:5|fillcolor:red|48.2,2.1|48.3,2.13|48.4,2.12&zoom=10&size=460x200&key=MY_API_KEY"
When I use this URL in my browser, I get the desired map.
When I use this URL in my app on Android, it displays the map correctly.
But when I use the same URL in my app on an iOS device, the map is not displayed at all.
Note: if I remove the path (e.g map_source: "https://maps.googleapis.com/maps/api/staticmap?&markers=48.2,2.1&zoom=10&size=460x200&key=MY_API_KEY", the image is correctly displayed on both Android and iOS. The error only appens when I add the path.
Is this an iOS issue or am I doing something wrong ?
I was able to find the issue thanks to #Manoj. On iOS devices, the URL was unsupported because of the "|" character. So I had to encode it like so:
let imageSourceModule = require("tns-core-modules/image-source");
let url = encodeURI("https://maps.googleapis.com/maps/api/staticmap?&markers=48.2,2.1&zoom=10&size=460x200&key=MY_API_KEY")
imageSourceModule.fromUrl(url).then(res => {
this.map_source = res;
});

How to copy from Storage to FileSystemStorage in Codenameone and display in BrowserComponent

I've been reading a lot of StackOverflow posts that discuss copying data from FileSystemStorage to Storage in CodenameOne, such as described in this answer from Shai, as seen below:
InputStream stream =
FileSystemStorage.getInstance().openInputStream(i);
OutputStream out =
Storage.getInstance().createOutputStream("MyImage");
Util.copy(stream, out);
Util.cleanup(stream);
Util.cleanup(out);`
I've been trying to do the reverse: save from Storage to FileSystemStorage in order to show a PDF in the BrowserComponent (while using iOS), but have not been able to do so. I need to show the PDF within the app (so I don't want to use Display.getInstance().execute()).
Basically, I'm trying to dynamically populate a Container with whatever files the user selects-- I am using the FileChooser library for CN1 from Steve Hannah. (Disclaimer: I have made slight modifications to this library as it used in the app I'm working on-- HOWEVER, when I choose images with this library and pull them from Storage to an Image via InputStream, they display perfectly in an ImageViewer so I know that all files are being saved correctly in Storage.)
Here is my code (with help from Steve Hannah's comment on GitHub):
//fileLocation and fileName are slightly different but both end with file extension
File file = new File(fileToUpload.getFileName());
FileSystemStorage fss = FileSystemStorage.getInstance();
InputStream is = Storage.getInstance().createInputStream(fileToUpload.getLocation());
OutputStream os = fss.openOutputStream(file.getAbsolutePath());
Util.copy(is, os);
ToastBar.Status status = ToastBar.getInstance().createStatus();
String message = file.exists() + " " + file.isFile() + file.getAbsolutePath();
status.setMessage(message);
status.setExpires(3000);
status.show();
NativeLogs.getNativeLogs();
if (Display.getInstance().getPlatformName().equals("ios")) {
//Log.p("in ios !!!!");
BrowserComponent browserComponent = new BrowserComponent();
browserComponent.setURL(file.getPath());
horizontalContainer.add(browserComponent);
}
The ToastBar displays true and true for file.exists() and file.isFile().
I stipulate iOS because as far as I've seen while researching previewing PDFs within an app, I've seen that Android needs to have a different implementation, like adding a NativeInterface with an Android library. I also saw in different answers on the Google Group that this functionality (using browserComponent to view PDFs) is only available for iOS and not on the simulator. In the simulator, I see a blank space. My iPhone just freezes and/or crashes after displaying the ToastBar (and I work on a Windows machine, so not much ability to see native logs....)
What can I do to access the file and show it in the BrowserComponent?
Thank you!
Simple solution -- the file had a space in it (eg. "Test page.pdf") and didn't show! When I used files that didn't have spaces this worked and after removing spaces in the file names, thankfully everything worked. I'll have to add code to handle this scenario.
Thanks for your help!

How can I persist Session data in a standalone web app after an external launch?

I have an MVC 5 mobile website that I am trying to make a standalone mobile web app running full screen on an iPhone. Everything works well until the app launches an external link that will, for example, launch in Safari. Upon returning to the web app the Session data seems to disappear and a new Session Id is assigned, wiping out any existing trace of previous user progress prior to the external launch. The User Name, however, remains intact and “logged in”. What do I need to do to persist the Session data?
I’ve been at this for hours now, googling and trying different approaches, but to no avail and my head is spinning. A similar post is HERE but my problem is the Session data.
Any help/direction would be greatly appreciated.
UPDATE 1
It seems that this behavior is limited to iOS -- currently testing on 9.3.3. Same behavior whether the "Back to [App] upper left link in the status bar is used or double-tap on the home button to return to WebApp. Android OSs seem to work just fine. Go figure. We are using cookies.
So it was a "Hail-Mary pass" but it worked... just persist the ASP.NET_SessionId cookie in javascript. It may have worked elsewhere but here's what I did:
In _Layout.vbhtml I added this to $(document).ready:
if (window.navigator.standalone || window.matchMedia('(display-mode: standalone)').matches) {
document.cookie = "ASP.NET_SessionId=#(Session.SessionID); " + extendTimeStr(5);
}
along with the function:
function extendTimeStr(extMins) {
var d = new Date();
d.setTime(d.getTime() + (extMins*60*1000));
return "expires="+ d.toUTCString();
}
Magically, it worked! Hope it helps someone.
Update for AspNetCore 2.0:
$(document).ready(function () {
if (('standalone' in window.navigator) && window.navigator['standalone']) {
var cookie = '#(Context.Request.Cookies[".AspNetCore.Identity.Application"])';
document.cookie = ".AspNetCore.Identity.Application=" + cookie + "; " + extendTimeStr(5);
}
})
Thank you #HumbleBeginnings for your excellent and simple solution to a problem I can't find answers to elsewhere!

Can I create an application in Mono for Android with Arduino?

Is it possible to create an application with Mono for Android and control Arduino without using Eclipse but using Visual Studio and C#?
I checked some examples but everyone uses Java and Eclipse.
Simply put, the answer is yes, it is possible. The real question is: How? I'm going to assume you've already written you first Android app with Mono.
Next, you need to decide how you will connect your Android device to the Arduino. Bluetooth? Wi-Fi? Web?
Next, it's simply a matter of using the appropriate Android API. Check out the Xamarin documentation for Android.
Update
Much more than what I present below is available with the ported MonoDroid sample applications. Specifically, you would be interested in the BluetoothChat example.
Make sure you also take a look at adding permissions to the manifest file, and of course, the Android Developer Guide for Bluetooth.
That said, here's a tiny something to get you started, based on Android Quick Look: BluetoothAdapter:
txtStatus.Text = "Getting Bluetooth adapter...";
BluetoothAdapter bluetooth = BluetoothAdapter.DefaultAdapter;
if( bluetooth == null )
{
txtStatus.Text = "No Bluetooth adapter found.";
return;
}
txtStatus.Text = "Checking Bluetooth status...";
if (!bluetooth.IsEnabled )
{
Toast.MakeText(this, "Bluetooth not enabled. Enabling...",
ToastLength.Short).Show();
bluetooth.Enable();
}
if (bluetooth.State == State.On)
{
txtStatus.Text =
"State: " + bluetooth.State + System.Environment.NewLine +
"Address: " + bluetooth.Address + System.Environment.NewLine +
"Name: " + bluetooth.Name + System.Environment.NewLine;
}
else
{
txtStatus.Text = "State: " + bluetooth.State;
}

Blackberry: Data not fully displayed in BB version 5.0 Operating System/lower such as BB bold3

I developed an application and it works well on OS6 (Operating System 6) but doesn't work well on OS5 (JDK 5.0). The main problem is that I get data via JSON and displays multiple labels on the screen to show the data but the vertical scroll doesn't go allow the user to scroll down beyond a certain point. This makes me wonder if the screen in OS5 have limited contents allowed to be drawn on it. snippet code is shown below
JSONArray json = new JSONArray(result);
for (int i = 0; i < json.length(); ++i)
{
JSONObject moleculevalue = json.getJSONObject(i);//get the json data object
String tdescription = moleculevalue.getString("Total Description");
if (tdescription == "") tdescription = "Not Applicable";
_fieldManagerMiddle.add(new SeparatorField());
_fieldManagerMiddle.add(new LabelField("Description: " + tdescription, Field.FIELD_HCENTER));
}
Data still exist but users cannot scroll below the screen view.
Can anyone tell me a workaround for this and possibly reasons for this. Thanks in advance.
Found solution:
I found out it was a problem with touch devices vs non-touch devices. Hence for non-touch devices, there is a need to set the label control to focusable by
changing
_fieldManagerMiddle.add(new LabelField("Description: " + tdescription, Field.FIELD_HCENTER));
to
_fieldManagerMiddle.add(new LabelField("Description: " + tdescription, Field.FIELD_HCENTER|Field.Focusable));

Resources