简体   繁体   English

下载JS文件并使用NativeScript作为后台服务运行

[英]Download JS file and run as background services with NativeScript

Is it possible to download an JS function (JS file) and run it as an background service in NativeScript? 是否可以下载JS函数(JS文件)并在NativeScript中将其作为后台服务运行?

I have an function in JS that I like to be able to update quickly from server (if there is a bug or so). 我在JS中有一个函数,希望可以从服务器快速更新(如果有错误,则可以)。 And run the script as an background service. 并将脚本作为后台服务运行。 I like to get data from health data and send push to user from the “script”. 我喜欢从健康数据中获取数据,然后从“脚本”向用户发送推送。

Please help me with any ideas how to do this or point me in the right direction. 请给我任何有关如何执行此操作的想法,或为我指明正确的方向。

Yes, you can. 是的你可以。 Download the JS file that has the business logic, require it with absolute path from the background service. 下载具有业务逻辑的JS文件,并要求它具有来自后台服务的绝对路径。 If you are using Webpack, then you must be careful with injecting or requiring dependencies. 如果使用Webpack,则在注入或需要依赖项时必须小心。 Probably pass anything as parameter, for example if you like access to Http module inside that downloaded file (function), pass it as an argument. 可能将任何内容作为参数传递,例如,如果您希望访问该下载文件(函数)中的Http模块,请将其作为参数传递。

Just in case if you need an example for background services, here you go. 以防万一,如果你需要后台服务的一个例子, 在这里你去。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM