I've followed best practices - or so I believe in developing my app, however, it will not despite best effort - restart after a terminate event. The app starts in the log - however, it will not relaunch my geo code.
In order to debug - I reviewed the sample app (which I believe is Ionic - I'm using a jquery builder) - and have taken the app, created a new app which only has a button on the screen to launch geo-location. I have a JS support file, and the balance which is-has been supplied via the builder I'm using (Appery.io).
The app functions wonderfully in foreground, background, and on Android, and produces the desired results both in the full app and in my sample app.
However, I'm stuck on getting the app to launch on IOS after terminate. Can you help? If I need to purchase paid support for this issue - and you believe you can help - I'm glad to make that investment as the restart is a business requirement.
Below - my Javascript, and I've attached my IOS project file - as exported from xCode as well as the log extract from startup , terminate, and then where it boots the app - but does not restart my geo-code..
========================================Javascript=====================
var berror = false;
var obluemarker;
var bgeoon = false;
var nlastloggedtime = 0;
var ngpsage = 60000;
var bstarted = false;
var BackgroundGeoLocation;
var dLastGeoPoint = new Date();
var dLastMotionPoint = new Date();
//var oGeoObject2Post = Apperyio.getModel('oGeo2Log');
dLastGeoPoint.setDate(dLastGeoPoint.getDate() - 1);
//fRestartGeo('reload');
//setTimeout( function(){ fRestartGeo('reload'); }, 30000) ;
function fRestartGeo( sMethod ) {
var bResult = false;
var bRestart = fLocalGet('bInSuspendMode', 'boolean');
console.log('In Geolocation restart method - for Method:' + sMethod + " and restart is set to :" + bRestart,toString() );
if ( !bRestart ) {
console.log('Not in restart mode....');
return false;
}
if (fLocalGet('bRestartingGeo', 'boolean')) {
console.log('Geo Restart already in progress...');
return false;
}
fLocalSet('bRestartingGeo', true);
if ((BackgroundGeoLocation === undefined || BackgroundGeoLocation === null) && window.window.BackgroundGeolocation !== undefined ) {
console.log('attempting to restart geolocation...')
fwatchmyposition();
console.log('Geo restart complete');
} else {
console.log('Background Geolocation already started or is undefined...');
}
fLocalSet('bRestartingGeo', 'false');
}
function fturnoffgeowatch(bForReal) {
//navigator.geolocation.clearWatch(geowatchID);
//geowatchID = 0;
if (bForReal === undefined || bForReal === null) {
bForReal = false;
}
if (BackgroundGeoLocation !== undefined && bForReal) {
BackgroundGeoLocation.stop();
localStorage.setItem('bGeoOn', false);
//BackgroundGeoLocation = undefined ;
}
return;
}
// Build a new fence in the Database with the current location ...
function fwatchmyposition() {
var adata;
var aSW;
var aNE;
var oSW;
var oNE;
var oOptions;
var nDistanceFilter = 30;
var nGPSLogFrequency = 30000;
var bDebug = true;
var sUrl = "https://api.appery.io/rest/1/db/collections/GeoEventHistory";
var nFastest = nGPSLogFrequency - 5000;
// I. Set up background geolocation....
console.log('Starting call to background GeoLocation......');
if ( (BackgroundGeoLocation === undefined || BackgroundGeoLocation === null) && window.BackgroundGeolocation !== undefined ) {
console.log('assigning background geolocation from window....');
BackgroundGeoLocation = window.BackgroundGeolocation;
}
if (BackgroundGeoLocation !== undefined) {
console.log('using IOS configuration.....');
oOptions = {
desiredAccuracy: 0,
stationaryRadius: 20,
startOnBoot: true,
stopTimeout: 5,
stopDetectionDelay: 3,
distanceFilter: nDistanceFilter,
locationUpdateInterval: nGPSLogFrequency,
activityRecognitionInterval: nGPSLogFrequency,
fastestLocationUpdateInterval: nFastest,
activityType: 'Other',
debug: bDebug, // <-- enable this hear sounds for background-geolocation life-cycle.
//url : sUrl ,
//params : oGeoObject2Post,
//headers : oHeaders,
stopOnTerminate: false // <-- enable this to clear background location settings when the app terms
}
try {
console.log('Starting Geolocation configure event....');
console.log(JSON.stringify(oOptions));
var bResult = fStartMotionServices();
BackgroundGeoLocation.configure(oOptions, fStartGeo, geoFailureFN);
//BackgroundGeoLocation.configure(fStartGeo, geoFailureFn, oOptions);
} catch (e) {
//alert('Error turning on Geolocation configuration: ' + e);
console.log('Error turning on Geolocation....');
}
//fUpdateGeoStructure();
} else {
console.log('Background Geolocation function not found....');
}
return;
}
function fStartGeo(state) {
bgeoon = true;
localStorage.setItem('bGeoOn', true);
console.log('background Geolocation configuration success');
console.log('- Current state: ', state);
console.log('- Geolocation - asking question - Am I enabled (should be not yet - false)?', state.enabled);
if (!state.enabled || state.enabled === undefined) {
try {
BackgroundGeoLocation.start() //fStartMotionServices); //geoCallbackFn, geoFailureFn);
console.log('started background GeoLocation');
} catch (e) {
console.log('Unable to start BackgroundGeoLocation Function...');
}
} else {
// services already started.... start the motion services....
console.log('background geoLocation already enabled...');
}
}
function fStartMotionServices() {
console.log('starting-re-configuring Motion and Location change services....');
//console.log('starting onlocation service...');
BackgroundGeoLocation.onLocation(fgeoCallbackFn);
//console.log('starting on motion service....');
BackgroundGeoLocation.onMotionChange(fGeoMotionCallback);
console.log('Complete with configure of location serverice and motion change services');
}
function fgeoCallbackFn(oLocation, nTaskID) {
// called when the device is in motion.....
// fLocalSet('nTaskID', taskId); - this confuses the Kill process - comment it out
//dCurrent = new Date();
// this is where the error is - no longer at the old number
// change this
console.log('The task id is :' , nTaskID );
/* check the difference in the current date - time against the setting for number of seconds - to process a geo - event... */
//fUpdateGeoStructure();
console.log('location change sensed-location is: ' + JSON.stringify( oLocation ) + 'task id: ' + nTaskID.toString() )
fFinishGeo( nTaskID ) ;
//fSeeIfInABoundary(location, taskId, false);
}
function fGeoMotionCallback(bIsMoving, olocation, nTaskID ) {
// called when the device stops or starts.....
var dCurrent = new Date();
// fLocalSet('nTaskID', nTaskId); - confuses the kill process .....
fLocalSet('bIsMoving', bIsMoving);
//
// log a geoEvent for the display - for sure here....
//
console.log('motion change sensed - location is: ' + JSON.stringify( oLocation ) + 'task id: ' + nTaskID.toString() )
fFinishGeo(nTaskID);
}
function geoFailureFN(error) {
console.log("Error starting geolocation :" + error);
fBackgroundGeoLocationError(error);
}
function fsetcurrentposition() {
// purpose of this function is to move the most recently stored position that is in local storage - to the object - ocurrentposition ( a google lat,lang object )
var nlat = Number(localStorage.getItem('s_lat'));
var nlong = Number(localStorage.getItem('s_long'));
[Software_Studio_Geolocation_Plugin.zip](https://github.com/transistorsoft/cordova-background-geolocation-SampleApp/files/404293/Software_Studio_Geolocation_Plugin.zip)
var options = {
lat: nlat,
lng: nlong
};
ocurrentposition = new google.maps.LatLng(nlat, nlong);
console.log('ocurrentposition is:' + ocurrentposition);
return;
}
function fFinishGeo(nTask) {
console.log('finishing call to geoLocation for ' + nTask);
if (BackgroundGeoLocation !== undefined) {
BackgroundGeoLocation.finish(nTask); // call the finish routine directly
}
return;
}
===========================End JS=============================
======== Relevant part of system log showing startup and then IOS restarting the app - but not the geo=========================================
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Aug 5 10:32:34 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โTSLocationManager โบ HTTP
Aug 5 10:32:34 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Aug 5 10:32:34 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โโ autoSync? 1
Aug 5 10:32:34 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โโ Network available? 1
Aug 5 10:32:34 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โโ Is already transmitting? 0
Aug 5 10:32:34 74-80-239-249 SpringBoard[6475]: No image found for recordID 0:13130c23cc96039:492111154.608188 yet we're being asked for a scale
Aug 5 10:32:42 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]:
<+37.33021261,-122.02671669> +/- 10.00m (speed 4.09 mps / course 91.50) @ 8/5/16, 10:32:42 AM Pacific Daylight Time
Aug 5 10:32:42 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Aug 5 10:32:42 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โTSLocationManager โบ didUpdateLocation
Aug 5 10:32:42 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Aug 5 10:32:42 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โโ enabled: 1
Aug 5 10:32:42 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โโ isMoving: 1
Aug 5 10:32:42 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โโ distanceFilter: 30.0
Aug 5 10:32:42 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: Delta d: 34.171386, df: 30.000000
Aug 5 10:32:42 74-80-239-249 assertiond[6479]: assertion failed: 15F34 13E230: assertiond + 15801 [3C808658-78EC-3950-A264-79A64E0E463B]: 0x1
Aug 5 10:32:42 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โบ createBackgroundTask: 27
Aug 5 10:32:42 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]:
<+37.33021261,-122.02671669> +/- 10.00m (speed 4.09 mps / course 91.50) @ 8/5/16, 10:32:42 AM Pacific Daylight Time
Aug 5 10:32:42 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Aug 5 10:32:42 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โTSLocationManager โบ Process Location
Aug 5 10:32:42 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Aug 5 10:32:42 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โ Median location accuracy: 10.0
Aug 5 10:32:42 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โ Increment odometer: 61074.1
Aug 5 10:32:42 74-80-239-249 assertiond[6479]: assertion failed: 15F34 13E230: assertiond + 15801 [3C808658-78EC-3950-A264-79A64E0E463B]: 0x1
Aug 5 10:32:42 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โ stopBackgroundTask: 27 OF (
)
Aug 5 10:32:42 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โ INSERT: 422F40FA-736B-4CDA-9516-4DF4C8B121D7
Aug 5 10:32:42 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Aug 5 10:32:42 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โTSLocationManager โบ HTTP
Aug 5 10:32:42 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Aug 5 10:32:42 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โโ autoSync? 1
Aug 5 10:32:42 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โโ Network available? 1
Aug 5 10:32:42 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โโ Is already transmitting? 0
Aug 5 10:32:42 74-80-239-249 SpringBoard[6475]: No image found for recordID 0:13130c23cc96039:492111162.593029 yet we're being asked for a scale
Aug 5 10:32:50 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]:
<+37.33020389,-122.02635116> +/- 10.00m (speed 3.86 mps / course 90.03) @ 8/5/16, 10:32:50 AM Pacific Daylight Time
Aug 5 10:32:50 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Aug 5 10:32:50 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โTSLocationManager โบ didUpdateLocation
Aug 5 10:32:50 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Aug 5 10:32:50 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โโ enabled: 1
Aug 5 10:32:50 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โโ isMoving: 1
Aug 5 10:32:50 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โโ distanceFilter: 30.0
Aug 5 10:32:50 74-80-239-249 assertiond[6479]: assertion failed: 15F34 13E230: assertiond + 15801 [3C808658-78EC-3950-A264-79A64E0E463B]: 0x1
Aug 5 10:32:50 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: Delta d: 32.408958, df: 30.000000
Aug 5 10:32:50 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โบ createBackgroundTask: 28
Aug 5 10:32:50 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]:
<+37.33020389,-122.02635116> +/- 10.00m (speed 3.86 mps / course 90.03) @ 8/5/16, 10:32:50 AM Pacific Daylight Time
Aug 5 10:32:50 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Aug 5 10:32:50 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โTSLocationManager โบ Process Location
Aug 5 10:32:50 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Aug 5 10:32:50 74-80-239-249 assertiond[6479]: assertion failed: 15F34 13E230: assertiond + 15801 [3C808658-78EC-3950-A264-79A64E0E463B]: 0x1
Aug 5 10:32:50 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โ Median location accuracy: 10.0
Aug 5 10:32:50 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โ stopBackgroundTask: 28 OF (
)
Aug 5 10:32:50 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โ Increment odometer: 61106.5
Aug 5 10:32:50 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โ INSERT: 9794E721-F8FE-4D93-9DEB-DC2629B569FA
Aug 5 10:32:50 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Aug 5 10:32:50 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โTSLocationManager โบ HTTP
Aug 5 10:32:50 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Aug 5 10:32:50 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โโ autoSync? 1
Aug 5 10:32:50 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โโ Network available? 1
Aug 5 10:32:50 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โโ Is already transmitting? 0
Aug 5 10:32:50 74-80-239-249 SpringBoard[6475]: Unbalanced calls to begin/end appearance transitions for <SBBannerButtonViewController: 0x7fd8c36062f0>.
Aug 5 10:32:50 74-80-239-249 SpringBoard[6475]: No image found for recordID 0:13130c23cc96039:492111170.589188 yet we're being asked for a scale
Aug 5 10:32:52 74-80-239-249 assertiond[6479]: assertion failed: 15F34 13E230: assertiond + 15801 [3C808658-78EC-3950-A264-79A64E0E463B]: 0x1
Aug 5 10:32:52 74-80-239-249 SpringBoard[6475]: BSXPCMessage received error for message: Connection interrupted
Aug 5 10:32:52 74-80-239-249 assertiond[6479]: assertion failed: 15F34 13E230: assertiond + 15801 [3C808658-78EC-3950-A264-79A64E0E463B]: 0x1
Aug 5 10:32:52 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: - CDVBackgroundFetch onAppTerminate
Aug 5 10:32:52 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: - stopping background-fetch
Aug 5 10:32:52 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Aug 5 10:32:52 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โTSLocationManager โบ Destroy
Aug 5 10:32:52 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Aug 5 10:32:52 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โโ stopOnTerminate: 0
Aug 5 10:32:52 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โบ Motion-detector: OFF
Aug 5 10:32:52 74-80-239-249 Software_Studio_Geolocation_Plugin[6530]: โ create stationary geofence, radius: 32
Aug 5 10:32:52 74-80-239-249 assertiond[6479]: assertion failed: 15F34 13E230: assertiond + 15801 [3C808658-78EC-3950-A264-79A64E0E463B]: 0x1
Aug 5 10:32:52 --- last message repeated 1 time ---
Aug 5 10:32:52 74-80-239-249 SpringBoard[6475]: UNNotificationRegistrarConnectionListener connection invalidated
Aug 5 10:32:52 74-80-239-249 SpringBoard[6475]: UNNotificationSchedulerConnectionListener connection invalidated
Aug 5 10:32:52 74-80-239-249 SpringBoard[6475]: No image found for recordID 0:94187a3c73e80fd0:492111172.452469 yet we're being asked for a scale
Aug 5 10:32:52 74-80-239-249 SpringBoard[6475]: Application 'UIKitApplication:io.appery.app.SoftwareStudioGeolocationPlugin[0x7565]' exited voluntarily.
Aug 5 10:32:52 74-80-239-249 assertiond[6479]: assertion failed: 15F34 13E230: assertiond + 15801 [3C808658-78EC-3950-A264-79A64E0E463B]: 0x1
Aug 5 10:32:52 74-80-239-249 assertiond[6479]: notify_suspend_pid() failed with error 7
Aug 5 10:32:52 74-80-239-249 SpringBoard[6475]: Unbalanced calls to begin/end appearance transitions for <SBBannerButtonViewController: 0x7fd8c371b530>.
Aug 5 10:33:06 74-80-239-249 backboardd[6476]: CoreAnimation: updates deferred for too long
Aug 5 10:33:06 74-80-239-249 SpringBoard[6475]: Reply Error: Connection interrupted
Aug 5 10:33:16 74-80-239-249 assertiond[6479]: assertion failed: 15F34 13E230: assertiond + 15801 [3C808658-78EC-3950-A264-79A64E0E463B]: 0x1
Aug 5 10:33:17 74-80-239-249 backboardd[6476]: SecTaskLoadEntitlements failed error=22 cs_flags=200, task->pid_self=-1
Aug 5 10:33:17 74-80-239-249 backboardd[6476]: SecTaskCopyDebugDescription: Software_Studio_[6896]
Aug 5 10:33:17 74-80-239-249 backboardd[6476]: SecTaskLoadEntitlements failed error=22 cs_flags=200, task->pid_self=-1
Aug 5 10:33:17 74-80-239-249 backboardd[6476]: SecTaskCopyDebugDescription: Software_Studio_[6896]
Aug 5 10:33:17 74-80-239-249 backboardd[6476]: SecTaskLoadEntitlements failed error=22 cs_flags=200, task->pid_self=-1
Aug 5 10:33:17 74-80-239-249 backboardd[6476]: SecTaskCopyDebugDescription: Software_Studio_[6896]
Aug 5 10:33:17 74-80-239-249 backboardd[6476]: SecTaskLoadEntitlements failed error=22 cs_flags=200, task->pid_self=-1
Aug 5 10:33:17 74-80-239-249 backboardd[6476]: SecTaskCopyDebugDescription: Software_Studio_[6896]
Aug 5 10:33:17 74-80-239-249 backboardd[6476]: SecTaskLoadEntitlements failed error=22 cs_flags=200, task->pid_self=-1
Aug 5 10:33:17 74-80-239-249 backboardd[6476]: SecTaskCopyDebugDescription: Software_Studio_[6896]
Aug 5 10:33:17 74-80-239-249 Software_Studio_Geolocation_Plugin[6896]: assertion failed: 15F34 13E230: libxpc.dylib + 57882 [66C28065-C9DB-3C8E-926F-5A40210A6D1B]: 0x7d
Aug 5 10:33:17 74-80-239-249 assertiond[6479]: assertion failed: 15F34 13E230: assertiond + 15801 [3C808658-78EC-3950-A264-79A64E0E463B]: 0x1
Aug 5 10:33:17 74-80-239-249 Software_Studio_Geolocation_Plugin[6896]: Apache Cordova native platform version 3.9.1 is starting.
Aug 5 10:33:17 74-80-239-249 Software_Studio_Geolocation_Plugin[6896]: Multi-tasking -> Device: YES, App: YES <<========= Restart tof the app.....
Aug 5 10:33:17 74-80-239-249 Software_Studio_Geolocation_Plugin[6896]: Unlimited access to network resources
Aug 5 10:33:17 74-80-239-249 assertiond[6479]: assertion failed: 15F34 13E230: assertiond + 15801 [3C808658-78EC-3950-A264-79A64E0E463B]: 0x1
Aug 5 10:33:57 --- last message repeated 1 time ---