Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-4875

iOS: Background services do not run when the app is locked

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Invalid
    • Affects Version/s: None
    • Fix Version/s: Sprint 2011-37
    • Component/s: iOS
    • Labels:
      None
    • Environment:

      Ti SDK: 1.7.1.1293a6d & 1.7.2.97c3689
      iOS SDK: 4.2 & 4.3
      Build Platform: OSX 10.6.8

      Description

      When running your app in the foreground, if you press the home button then background services work as expected, however if you "Lock" the device (CMD+L in the simulator, top button on the device) then the background code never runs.

      Here's how to reproduce it in two simple files that can be dropped into a new project.

      app.js:

      var w = Ti.UI.createWindow(); 
      var bgsvc = Ti.App.iOS.registerBackgroundService({ url: '/bg.js' }); 
      Ti.App.addEventListener('pause', function(e) { 
              Ti.API.debug("pause fired"); 
      }); 
       
      Ti.App.addEventListener('resumed', function(e) { 
              Ti.API.debug("resumed fired"); 
      }); 
       
      w.open(); 
      

      bg.js:

      Ti.API.debug("Hi from bg.js, about to loop forever"); 
      function bgfunc() { 
              setTimeout(bgfunc, 5000); 
              Ti.API.debug("Hi from bgfunc"); 
      }
      bgfunc();
      

      Running the above code I see the following when pressing the home button:

      [INFO] bgtest/1.0 (1.7.1.1293a6d) 
      [DEBUG] Analytics is enabled = YES 
      [DEBUG] loading: /Users/evan/Projects/Titanium/bgtest/Resources/ 
      app.js, resource: Users/evan/Projects/Titanium/bgtest/Resources/app_js 
      [DEBUG] application booted in 28.014004 ms 
      [DEBUG] fire app event: pause 
      [DEBUG] pause fired 
      [DEBUG] loading: /Users/evan/Projects/Titanium/bgtest/Resources/bg.js, 
      resource: Users/evan/Projects/Titanium/bgtest/Resources/bg_js 
      [DEBUG] Hi from bg.js, about to loop forever 
      [DEBUG] Hi from bgfunc 
      [DEBUG] Hi from bgfunc 
      ... continues every 5 seconds ... 
      [DEBUG] fire app event: resumed 
      [DEBUG] resumed fired 
      

      But if I run the app and push the lock button I get:

      [INFO] bgtest/1.0 (1.7.1.1293a6d) 
      [DEBUG] Analytics is enabled = YES 
      [DEBUG] loading: /Users/evan/Projects/Titanium/bgtest/Resources/ 
      app.js, resource: Users/evan/Projects/Titanium/bgtest/Resources/app_js 
      [DEBUG] application booted in 27.069032 ms 
      [DEBUG] fire app event: pause 
      [DEBUG] pause fired 
      ... wait 10 seconds, unlock ... 
      [DEBUG] fire app event: resumed 
      [DEBUG] resumed fired 
      

      I have found a similar question on the developers site: http://developer.appcelerator.com/question/116667/ios-background-geolocation-in-16

      In the second comment there is a link to a github URL that contains a fork of titanium: https://github.com/mpociot/titanium_mobile/commit/4853f091639e899545f9d1ef1416b1ca5baa0746

      The code in the fork seems to address the issue and enables background services to run on lock. Can this be merged into Titanium?

        Attachments

          Activity

            People

            • Assignee:
              rseagraves Reggie Seagraves
              Reporter:
              evan Evan Borgstrom
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-4142
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Integration