dpa99c / phonegap-launch-navigator

Phonegap/Cordova plugin which launches native route navigation apps for Android, iOS and Windows
369 stars 131 forks source link

Inactivity causes map not to launch (iOS 11.X.X) #173

Closed PointmanDev closed 6 years ago

PointmanDev commented 6 years ago

The first time the navigator is launched, it works fine. A user selects a default map application and chooses to save it. Launching the navigation continues to work as long as the app stays open. However, after 5 minutes of inactivity (the app in the background or the screen locked), the navigation ceases to work. Only an app restart allows it to start working again.

This happens only on iOS, all devices running iOS 11.X.X

Sample code launchnavigator.navigate(strAddress, function(){ MobileTech.utils.Helper.debugLog('Navigation Launched'); }, function(error){ if(error !== 'cancelled'){ Ext.Msg.alert(MobileTech.utils.Messages.Application.Map.NavigationNotAvailableTitle, error); } });

Sample address supplied: "378 Cottonwood Dr Williamsville NY 14221". This address works when the navigation button works.

I SUSPECT that the culprit is WebSQL. I see that it is being used to store the user's choice of which app to use (via localforage). I have identified that on iOS 11+, the connection to WebSQL database becomes inactive after 5 minutes, so calls made on a reference to an open database fail. I had a similar problem with another WebSQL database and now check the reference to confirm it is not null or undefined, that the version property is not null or undefined, and that the version is not equal to a blank string. If any of these tests fail, I call openDatabase again and reset the variable.

This was a new behavior introduced in iOS 11 and does not happen on older versions of iOS.

PointmanDev commented 6 years ago

When the navigate method is called, the following errors appear in the debugger (XCODE). This appears regardless of whether launching works or does not work.

2017-12-18 23:02:03.899300-0500 App[2096:838470] -canOpenURL: failed for URL: "citymapper://" - error: "The operation couldn't be completed. (OSStatus error -10814.)" 2017-12-18 23:02:03.900704-0500 App[2096:838470] -canOpenURL: failed for URL: "navigon://" - error: "The operation couldn't be completed. (OSStatus error -10814.)" 2017-12-18 23:02:03.901504-0500 App[2096:838470] -canOpenURL: failed for URL: "transit://" - error: "The operation couldn't be completed. (OSStatus error -10814.)" 2017-12-18 23:02:03.902202-0500 App[2096:838470] -canOpenURL: failed for URL: "tomtomhome://" - error: "The operation couldn't be completed. (OSStatus error -10814.)" 2017-12-18 23:02:03.903704-0500 App[2096:838470] -canOpenURL: failed for URL: "waze://" - error: "The operation couldn't be completed. (OSStatus error -10814.)" 2017-12-18 23:02:03.904414-0500 App[2096:838470] -canOpenURL: failed for URL: "yandexnavi://" - error: "The operation couldn't be completed. (OSStatus error -10814.)" 2017-12-18 23:02:03.905081-0500 App[2096:838470] -canOpenURL: failed for URL: "com.sygic.aura://" - error: "The operation couldn't be completed. (OSStatus error -10814.)" 2017-12-18 23:02:03.905769-0500 App[2096:838470] -canOpenURL: failed for URL: "here-route://" - error: "The operation couldn't be completed. (OSStatus error -10814.)" 2017-12-18 23:02:03.906503-0500 App[2096:838470] -canOpenURL: failed for URL: "moovit://" - error: "The operation couldn't be completed. (OSStatus error -10814.)" 2017-12-18 23:02:03.907523-0500 App[2096:838470] -canOpenURL: failed for URL: "mapsme://" - error: "The operation couldn't be completed. (OSStatus error -10814.)" 2017-12-18 23:02:03.908011-0500 App[2096:838470] THREAD WARNING: ['LaunchNavigator'] took '10.115723' ms. Plugin should use a background thread.

dpa99c commented 6 years ago

The canOpenURL URL errors are nothing to worry about. They are a side effect of the plugin's use of the core canOpenURL function to determine which apps are installed on the device via their custom URL schemes. canOpenURL logs an error to the console if the URL can't be opened, but in this case we expect an error if the queried URL scheme relates to an app which is not currently installed.

However, regarding the WebSQL, I will check that I can reproduce this on iOS 11 and if so move to using a native SQLite DB to store the data (with a migration shim to move any data currently in WebSQL).

PointmanDev commented 6 years ago

Dave, I did cloned the repo to do some testing and removing the code that checks if the store exists around the call to local forge to set the store in ensureStore also fixes the issue. This causes the connection to the db to be opened before every call.


Steve Raines Chief Innovation Officer raines@pointmanhq.com tel:800-299-2079 fax:716-842-1762

403 Main Street, Suite 200 | Buffalo, NY 14203

This e-mail message may contain confidential or legally privileged information and is intended only for the use of the intended recipient(s). Any unauthorized disclosure, dissemination, distribution, copying or the taking of any action in reliance on the information herein is prohibited. E-mails are not secure and cannot be guaranteed to be error free as they can be intercepted, amended, or contain viruses. Anyone who communicates by e-mail is deemed to have accepted these risks.


From: Dave Alden notifications@github.com Sent: Tuesday, December 19, 2017 3:57:58 AM To: dpa99c/phonegap-launch-navigator Cc: PointmanDev; Author Subject: Re: [dpa99c/phonegap-launch-navigator] Inactivity causes map not to launch (iOS 11.X.X) (#173)

The canOpenURL URL errors are nothing to worry about. They are a side effect of the plugin's usehttps://github.com/dpa99c/phonegap-launch-navigator/blob/master/src/ios/LaunchNavigator.m#L1227 of the core canOpenURLhttps://developer.apple.com/documentation/uikit/uiapplication/1622952-canopenurl function to determine which apps are installed on the device via their custom URL schemes. canOpenURL logs an error to the console if the URL can't be opened, but in this case we expect an error if the queried URL scheme relates to an app which is not currently installed.

However, regarding the WebSQL, I will check that I can reproduce this on iOS 11 and if so move to using a native SQLite DB to store the data (with a migration shim to move any data currently in WebSQL).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/dpa99c/phonegap-launch-navigator/issues/173#issuecomment-352679944, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AcqIjXFfR8StUMb3dGU3ey8Ab8becsQBks5tB3qVgaJpZM4RGdAr.

dpa99c commented 6 years ago

So commenting out if(!store) on line 51 so localforage.createInstance() is called every time, and this causes openDatabase() to be called every time?

PointmanDev commented 6 years ago

For WebSQL, I believe there is openDatabase, and localForge's createInstance method abstracts it because it can support localStorage, or webSQL, or IndexDB.

The working code change is:

var ensureStore = function(){
   //if(!store){
        store = localforage.createInstance({
            name: "launchnavigator"
        });
   // }
};

The store object itself exists, even though the database connection is closed, so when the conditional check is in there, it fails. always calling createInstance tells localforage to get the database reference each time.

It may be a slight performance hit but guarantees that the connection exists.

dpa99c commented 6 years ago

It may be a slight performance hit but guarantees that the connection exists.

Since it's not like the plugin method is going to be called every 10ms, I'm going to go ahead and implement this in the plugin.

PointmanDev commented 6 years ago

Thank you!!!


Steve Raines

Co-founder, Pointman

raines@pointmanhq.com

tel:800-299-2079

fax:716-842-1762

403 Main Street, Suite 200 | Buffalo, NY 14203

This e-mail message may contain confidential or legally privileged information and is intended only for the use of the intended recipient(s). Any unauthorized disclosure, dissemination, distribution, copying or the taking of any action in reliance on the information herein is prohibited. E-mails are not secure and cannot be guaranteed to be error free as they can be intercepted, amended, or contain viruses. Anyone who communicates by e-mail is deemed to have accepted these risks.

From: Dave Alden notifications@github.com notifications@github.com Reply: dpa99c/phonegap-launch-navigator reply@reply.github.com reply@reply.github.com Date: December 19, 2017 at 3:08:09 PM To: dpa99c/phonegap-launch-navigator phonegap-launch-navigator@noreply.github.com phonegap-launch-navigator@noreply.github.com Cc: PointmanDev raines@pointmanhq.com raines@pointmanhq.com, Author author@noreply.github.com author@noreply.github.com Subject: Re: [dpa99c/phonegap-launch-navigator] Inactivity causes map not to launch (iOS 11.X.X) (#173)

It may be a slight performance hit but guarantees that the connection exists.

Since it's not like the plugin method is going to be called every 10ms, I'm going to go ahead and implement this in the plugin.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dpa99c/phonegap-launch-navigator/issues/173#issuecomment-352871975, or mute the thread https://github.com/notifications/unsubscribe-auth/AcqIjTVn5vZ7tBewKFX78tHGPXZcZEeMks5tCBengaJpZM4RGdAr .