I'm using this handy Cordova plugin to set application settings from the homepage of my Cordova iOS hybrid app:
https://github.com/escio/cordova-ios-application-preferences
I have a local hybrid app and from the index.html homepage, and I set an application preference when a user clicks a button, using this plugin.
On success of setting the application preference, I have confirmed via logging that the setting is correctly set. At that point, I call a JS function that looks at the application preferences. What's weird is that although the log indicates that I've set the preference correctly, my JS function is still using/referring to the default value for that preference. If I exit the app and restart it immediately, it's clearly working with the newer application preference but on that initial flow, the app appears to be using a cached version of the application preference.
Any ideas here? How can I get Cordova to use the current application preference?
To close the loop on this, I discovered that although the plugin was setting the value, the hybrid app had a bunch of native code running and the settings values were grabbed by the app at initialization. So in addition to setting the new value in the Application Preferences, I had to add a small method call into the plugin, in objective-c, to set the new value on the native side of the application memory/state.
Related
I have made an angular + workbox application that now is converted using PWABuilder to Cordova project targeting ios platform.
Now my problem started with offline page, I want my application to work the same way it works on chrome browser with offline mode.
That is, even if I'm in offline mode, I'm able to use website and store the requests for later on.
But on IOS device, when I open application, then turn airplane mode or disconnect wifi and re-run an app a white screen appears. (Offline page support is disabled in manifest.js - I don't need Offline.html)
I have registered routing by
workbox.routing.registerNavigationRoute('/');
And then
// couple of following lines:
workbox.routing.registerRoute('regex with js,manifest...etc', networkFirstStrategy({cacheName} ...)
And the weird fact is that on ios this somehow can't be cached, or somethings different happens.
I'm waiting for any suggestions, or leads that can help me fix this behaviour.
Answer
The WebView as used by Cordova in the latest iOS (12.0.1) will not run Workbox because it doesn't support Service Workers.
Details
Cordova apps run in a WebView.
The app executes in a WebView within the native application wrapper... source
The WebView in the latest production iOS (12.0.1) only supports Service Workers within three specific contexts, which doesn't include Cordova apps.
At this time [the Service Worker API] is only available in Safari, applications that use SFSafariViewController, and web applications saved to your home screen. source
Next Steps
It may be possible to add Service Worker support via a Cordova Plugin. For example: cordova-plugin-service-worker.
In addition, you may also need to add Background Sync support as the latest Safari does not support Background Sync. For example: cordova-plugin-service-worker-background-sync.
The Workbox docs state that they provide a fallback strategy when Background Sync is not supported:
Workbox Background Sync...also implements a fallback strategy for browsers that
don't yet implement BackgroundSync. source
However, an open issue on Github shows that the fallback strategy may not work on iOS.
I'm using xcode with an angular/ionic framework hybrid app for cordova. On my windows machine, I've been able to build and run for blackberry and android with this code successfully so I'm not sure what's not right. The back end is a Microsoft Web API restful service with basic windows authentication from active directory sending back JSON serialized data.
The main data call boils down to:
$http.get('http://192.168.0.12/api/values/1').
success(onSuccuess).
error(onFailure);
I'm sure I have the usual in the config and NSAllowsArbitraryLoads on the info.plist. I also have the most permissible "Content-Security_policy" meta tag on the main index.html file.
I'm fairly sure none of these are the issue because the loads will immediately fail in the safari development simulator dialog. My issue is that the load simply never finishes. If I double click the resource name in the "Network" tab, safari will open and load the data appropriately.
Again, this fails in the osx simulator and on a device hooked to the network. But works fine on my physical blackberry (Z10 lol) and android simulator on my windows machine.
I'm using localStorage in my hybrid mobile app, which is developed using ionicFramework. Everything works fine, except localStorage uncertain behavior in IOS.
It works fine in Android.
Bug Scenario:
App login -> Use App -> Put the app to background
Don't use it for almost 4 hours -> Open the app
The localStorage gets empty. (And the app is logged out because the token from the localStorage is also missing)
Now force quit the app,and reopen it. All the localStorage values are restored and the app is again logged in. (mean missing values are again recovered).
I'm following the standard way to use localStorage i.e.
window.localStorage.setItem('key', value);
window.localStorage.getItem('key');
window.localStorage.removeItem('key');
I also used AngularLocalStorage, but it also had the same problem, because AngularLocalStorage is a wrapper over Local Storage...
Cordova 5.4.1
IONIC Platform 1.1.1
I am developing an app with Cordova for iOS which includes geolocation functionalities (I use the official plugin https://github.com/apache/cordova-plugin-geolocation). I saw in options of my app that location access can be either set as "Never" or "While Using the App". However some other apps may also the option "Always" as shown in the attached screenshot. I would like to know whether it is possible to also have the option "Always" for Cordova-based applications.
Thanks!
I was using both NSLocationWhenInUseUsageDescription and NSLocationAlwaysUsageDescription in my company's Cordova app and it was working. Then, in late 2017, it stopped.
The fix for me has been to add also NSLocationAlwaysAndWhenInUseUsageDescription.
More broadly speaking, note that you need to have a plugin allowing to track location in background as well as make sure that the necessary background mode option is enabled in XCode.
We use the following plugin to do the job:
https://www.npmjs.com/package/cordova-plugin-lents-background-geolocation
This type of plugin is necessary as iOS stops execution of scripts for apps roughly 3 minutes after the display is turned off, regardless of the app foreground/background condition when the display was turned off. This prevents any JavaScript code to run and therefore any GPS tracking based on setInterval or setTimeout will stop working.
I guess "NSLocationAlwaysUsageDescription" key is the one which you are looking for. Check out this link which details the settings to be done in cordova based applications to have constant location access.
I'm using Ionic 2 and had to add the following to my App-Info.plist file. Even though cordova inserts 'NSLocationAlwaysUsageDescription' and 'NSLocationWhenInUseUsageDescription' keys. This only gave a 'Never' and 'While Using App' option on launch. Xcode suggested using the option below and that worked for me.
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This app requires background location tracking</string>
There are many ways to start application from another application in Android.
Is it possible to start application from another application in iOS? If possible, how do I do it?
Yes, it is possible in iOS if provided the app has its URL Scheme set. If you want to open your app from any other your app you can set the custom URL Scheme in info tab of project settings.
To test, run your app, minimize and then open safari and type the URL you just set, hit GO and your app will open.