Вопрос

I am having a weird bug where the background service in iOS doesn't start the first time I hit the home button.

My code is simple:

//-- app.js
Ti.App.addEventListener('paused', function(event)
{
    Ti.API.info('paused');
    var bgService = Ti.App.iOS.registerBackgroundService({
       url: 'includes/services/ios_bgservice.js'
    });
});

//-- ios_bgservice.js
Ti.API.warn('bg logout process has begun for iOS');

My process is:

  • compile/launch app in emulator
  • simulate the home button (cmd + shift + h)
  • console shows ONLY "paused". I should see "paused [new line] bg logout process has begun for iOS"

If I launch the app again via the dashboard (Do not recompile), then hit the home button, the console shows paused [new line] bg logout process has begun for iOS

This had to break somewhere around this year because I know at one point it was working. I have also confirmed the behavior is the same when tested on the device.

Additional Info

  • Ti Studio, build: 3.1.3.201309132423
  • Ti SDK 3.1.3 GA
  • iOS7 SDK
Это было полезно?

Решение

Well, it's pretty simple. You cannot register a web service after your application has paused.

You simply write the following lines and your service will automatically be triggered, when your application goes in pause state

var service = null;
if(service != null){
service = Ti.App.iOS.registerBackgroundService({
       url: 'includes/services/ios_bgservice.js'
    });
}

Hope this Helps !!!

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top