Hi, I am using SK 3.5.1GA, Appc 4.0 - testing on an iOS 7 device and iOS8 emulator
I am trying to create a simple background sevice that runs the location service (at low power) and then simply update my local database with some info. My problem is that it doesn't seem to run for long in the background. After backgrounding the app for 40 mins, I see only 1 record from the interval and only 1 record from the location service timestamped when the app resumes. It looks like the sevice doesn't run for more than 2 mins.
I am hoping someone can glance quickly at this and see what I am doing wrong.
This is my setup
//... //TIAPP.xml <ios> <plist> <dict> ... <key>UIBackgroundModes</key> <array> <string>location</string> </array> </dict> </plist> </ios>
//... //APP.JS ... var bgService; ... Ti.App.addEventListener('resumed', function(){ ... //BG location stuff? if (bgService != null){ bgService.stop(); bgService.unregister(); } }); Ti.App.addEventListener('pause', function(){ ... //BG location stuff? bgService = Ti.App.iOS.registerBackgroundService({url:'/lib/bg.js'}); });
// /lib/bg.js //This holds the process for the background service that wil run on iOS var timerDuration = 120000; var callbackDT; Ti.Geolocation.distanceFilter = 50; Ti.Geolocation.accuracy = Ti.Geolocation.ACCURACY_LOW; //This is the location callback that means Geo locating will be running in the background continuously var locationCallback = function(e) { if (e.coords && e.success !== undefined) { e = e.coords; if(e !== undefined){ callbackDT = new Date(); var _db = Ti.Database.open('lclVB'); _db.execute("INSERT INTO tbl_GeoTest(created, msg, lat, lon, speed, acc) VALUES(?,?,?,?,?,?)", callbackDT.toString(), 'paused location callback', e.latitude, e.longitude, e.speed, e.accuracy ); _db.close(); } } }; Ti.Geolocation.addEventListener('location',locationCallback); //This is a quick interval check to see how long the process stays up setInterval(function(){ var tmpCreated = new Date(); var _db = Ti.Database.open('lclVB'); _db.execute("INSERT INTO tbl_GeoTest(created, msg, lat, lon, speed, acc) VALUES(?,?,?,?,?,?)", tmpCreated.toString(), 'paused interval check', 0, 0, 0, 0 ); _db.close(); },timerDuration);