Background scanning nativescript-vue

plugins

#1

Dear all,

I am using the following plugin to scan for bluetoothdevices:

I am using nativescript-vue and would like to perform scanning on the background. I read this piece on the docs: https://docs.nativescript.org/core-concepts/ios-runtime/how-to/BackgroundExecution

But how should i use this within nativescript-vue(npm)?
I read this article: https://www.nativescript.org/blog/using-plugins-in-a-nativescript-vue-app but am afraid this won’t help me with what I’m trying to achieve.

How would you guys go about background scanning within nativescript-vue?

Kindest regards,
Stijn


#2

This plugin doesn’t involve any UI component, so you have nothing specific to do with Vue. Use it just like any other JavaScript library you would use in Vue.


#3

But how do i do background scanning in nativescript-vue?
The question was not that clear probably


#4

The plugin gives you JS interface for native apis, bluetooth.startScanning(..) gives you everything - you are not directly accessing any native apis here so I don’t really get what exactly is the issue you are facing in calling these methods.


#5

Forget about the plugin, it is non important, I have 0 issues with the plugin.

I want to execute a method in the background from vue; i have this method:

sayHello(){
    console.log('Hello!');
},

I want to invoke this method every 30 seconds when the app is not opened.
It is not open in recent apps either. Just a backgroundtask.


#6

Do not use a function from Vue’s context, just use a simple JavaScript function.


#7

And how would I do that?

Currently I have an interval set in mounted():

mounted() {
    this.scanInterval = setInterval(function () {
        this.start();
    }.bind(this), 30000); 
}

This unfortunately only works for approximately 3 minutes after the user closed the application.

I tried workers but they too are killed when the main thread is stopped.

So how do I create a background task in javascript that is running even when the application is closed (not in recent apps anymore) and runs every 30 seconds?


#8

Just refer the demo app, you can use the same code.

Which platform and OS version you are testing it with?


#9

The minimum is 15min.

I want the job to run every 30 seconds, maybe even more.
Whatsapp is instantly receiving messages, how do we do that?

I am debugging on a Samsung Galaxy S7(SM-930F) running Android 8.0.0
As for iOS I don’t know yet, I do not have access to an Apple device at the moment.


#10

Sorry, I’m very much confused now. Is it about working with bluetooth or running a background job?


#11

Backgroundjob

I want to send the location determined by beacons to the server in the backgroundjob
Every 30 seconds even when the app is in the background or killed.


#12

You have found the perfect example for background services already. You can register a broadcast receiver to get updates immediately, check available options in the official android docs.