Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23205] Windows: Background service extension by native module (C++/CX).

GitHub Issuen/a
TypeNew Feature
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2016-04-18T22:43:34.000+0000
Affected Version/sRelease 4.0.0
Fix Version/sRelease 5.4.0
ComponentsWindows
Labelsn/a
ReporterKota Iguchi
AssigneeKota Iguchi
Created2016-04-13T00:31:34.000+0000
Updated2016-07-07T15:17:23.000+0000

Description

Relates to TIMOB-18952 After lots of investigation & trial, I almost came up with a conclusion that it is _not_ possible to enable JavaScript/Ti context in background service. It's obviously too much to have two JavaScript/Ti instances at once (foreground & background), and the platform does not allow it. It's too much enough to screw up things (app freeze / device forced to restart, etc). We have one more choice so far then: which is *Implement background trigger extension by native module (C++)*. This should enable native module to react when background trigger is fired. Because it's a native module, you should be able to do anything you need. This means you need to code with C++ instead of JS (too bad) but at least we have last resort to implement custom logic.

Comments

  1. Jörgen Buder 2016-04-13

    If this direction is working we need to access the following APIs and I have the following questions how to handle, the solution must be able to "communicate" with these Ti context things even if we do not write the code in JS. Also please note how I need to bring into the callback other APIs and classes to be able to extend the callback with notifications and encryption.... Q: How do we transfer data (Ti.Platform.Properties) to the main app, and back? We use 4 critical flags saved into this API to take decisions in the background as well as save the last known location to the front app... Can we use the fire event API? How do we update a collection after receiving HTTP response? Currently I am trying hard to enable the native encryption libraries in a module to support the encryption HTTP post and get commands, we have to make one POST and one GET with encrypted data. Also we have to be able to create notifications and/or receive push notifications in the app.. There might be more that I oversee right now but basically this is it..
  2. Jörgen Buder 2016-04-13

    As I try to get things running in the module, can I ask you to verify if this log is working for you with the Emulator? Mine is not and I desperately need a way to debug the native code in the module.. TITANIUM_LOG_DEBUG("Extendwindows:: called genKey()"); ?? thanks
  3. Jörgen Buder 2016-04-13

    BTW I have a module we could use, if you need to have context, to use as template for such a native callback... I have to aim for collect location, encrypt data and send to server at the moment, later I will have to get http from server and create notification... FYI
  4. Kota Iguchi 2016-04-14

    FYI I'm updating [module template](https://github.com/appcelerator/titanium_mobile_windows/blob/master/templates/module/default/template/windows/src/%7B%7BmoduleIdAsIdentifier%7D%7D.cpp.ejs#L49) and [background task](https://github.com/infosia/titanium_mobile_windows/blob/TIMOB-23205-PR/Source/Ti/src/App/BackgroundService.cpp#L24) to show examples on HAL/TitaniumKit API. For the debug log, I guess it's because module is built with release mode ... I'll check.
  5. Jörgen Buder 2016-04-14

    Ok, not sure what it means, is there anything I can test, running a native background code that actually i.e. updates the count parameter so I can see if it runs continuously?
  6. Kota Iguchi 2016-04-14

    Yes, and it is a good example of how to implement background tasks. It's not merged yet but will be soon. Note that Titanium background task class uses very standard WinRT [IBackgroundTask](https://msdn.microsoft.com/library/windows/apps/br224794) interface. It means you should be able to actually create your backgroudn task as stand-alone Windows Phone project using Visual Studio, and once you finishes the test you can just copy/paste your logic to the module. I think it's the easiest way to debug it. FYI I found official sample code of WinRT background task API: https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/BackgroundTask (Take a look at cpp sample because Titanium is using C+\+/CX )
  7. Kota Iguchi 2016-04-15

    https://github.com/appcelerator/titanium_mobile_windows/pull/619
  8. Ewan Harris 2016-07-07

    Verified using: Windows 10 Pro Ti SDK: 5.4.0.v20160705213725 Appc NPM: 4.2.7-2 Appc CLI: 5.4.0-26 Appc Studio: 4.7.0.201606220541 Lumia 930: 10.0 Lumia 520 : 8.1 By creating a module, and following https://wiki.appcelerator.org/display/guides2/Windows+Background+Service+Quick+Start a user can create a background task with custom logic that will be triggered by a timer. Closing ticket

JSON Source