transistorsoft / nativescript-background-fetch Goto Github PK
View Code? Open in Web Editor NEWiOS Background Fetch API Implementation for NativeScript
License: Other
iOS Background Fetch API Implementation for NativeScript
License: Other
Hi :)
Plugin is working fine on Android
device.model LLD-L31
device.deviceType Phone
device.os Android
device.osVersion 9
device.sdkVersion 28
Is there an easy way to continue receiving Headless events in intervals after the phone has been rebooted/turned on again ?
I have
"startOnBoot" : true
in the configuration
Hi
I have been trying this for days and it never gets triggered when app is in background no matter of whether i use 15, 20 or 30 minutes. It does work when i use the simulator to trigger a fetch like event. Any idea what's going on?
HI,
I am trying to enable this plugin for a vue.js application. Can you help me to add this in the required main.js file? Do you have an example?
Kind regards,
Douwe
I am attempting to update to v1.1.1 and I get the following errors on compilation:
node_modules/nativescript-background-fetch/background-fetch.ios.d.ts(3,59): error TS2304: Cannot find name 'UIApplication'.
node_modules/nativescript-background-fetch/background-fetch.ios.d.ts(8,28): error TS2304: Cannot find name 'UIBackgroundFetchResult'.
Hi I have a problem, I installed the plugin but when import using
import {BackgroundFetch} from "nativescript-background-fetch"
gives me this error: Cannot read property 'CompletitionHandler' of undefined
Why ?
I performed the import in the app.js file, I tested the app on android 8.0.2
Hello,
Thanks for the plugin. How can I display notification of new information?
Thanks
In the readme for setup it is stated to do the following:
if (app.ios) {
class MyDelegate extends UIResponder implements UIApplicationDelegate {
public static ObjCProtocols = [UIApplicationDelegate];
// BackgroundFetch delegate method
public applicationPerformFetchWithCompletionHandler(application: any, completionHandler:any) {
BackgroundFetch.performFetchWithCompletionHandler(completionHandler);
}
}
app.ios.delegate = MyDelegate;
}
However, this has created some problems in my application. A lot of other plugins use the app delegate to perform numerous tasks. For instance the nativescript-firebase-plugin uses it to do google/facebook authentication and push notifications.
I have fixed this problem by utilizing the following code inside my Nativescript Angular app instead:
if (application.ios) {
application.ios.delegate.prototype.applicationPerformFetchWithCompletionHandler = function (application: any, completionHandler: any) {
BackgroundFetch.performFetchWithCompletionHandler(completionHandler);
};
}
I took this method from the firebase plugin code. This allows other plugins to continue utilizing the app delegate without interruption. I don't know if it will work in base nativescript or not. It may be possible to incorporate this directly into the plugin (like the firebase plugin), but I am not sure.
I had a runtime error in iOS "Error: Value is not a class."
This was resolved by changing my TSConfig to "ES5" instead of ES6 or ES2015. As far as I know this is only an issue on iOS.
I recommend putting a heads up in the readme regarding this common error so people can easily find the known solution / workaround.
Argument of type 'UIApplicationState' is not assignable to parameter of type 'Function'.
When trying to build for iOS this error keeps popping up for the below line. I've followed the instructions and have the references.d.ts
setup.
BackgroundFetch.performFetchWithCompletionHandler(completionHandler, application.applicationState);
i have added plugin in nativescript angular app, but not able to find solution for angular like how can i have a function which run on background after some time.
Hi, I am trying to use nativescript-background-fetch in Android App but it gives me error that BackgroundFetch.configure is not a function. I am using Javascript to develop android native app. My code in home-view-model.js is as below:
const observableModule = require("data/observable");
var permissions = require('nativescript-permissions');
var BackgroundFetch = require("nativescript-background-fetch");
function HomeViewModel() {
const viewModel = observableModule.fromObject({
/* Add your view model properties here */
onButtonTap: function () {
console.log(BackgroundFetch);
BackgroundFetch.configure({
minimumFetchInterval: 15, // minutes
stopOnTerminate: false, // Android-only
startOnBoot: false // Android-only
}, () => {
console.log("[js] BackgroundFetch event received");
//
// Do stuff. You have 30s of background-time.
//
// When your job is complete, you must signal completion or iOS can kill your app. Signal the nature of the fetch-event, whether you recevied:
// FETCH_RESULT_NEW_DATA: Received new data from your server
// FETCH_RESULT_NO_DATA: No new data received from your server
// FETCH_RESULT_FAILED: Failed to receive new data.
BackgroundFetch.finish(BackgroundFetch.FETCH_RESULT_NEW_DATA);
}, (status) => {
console.log('BackgroundFetch not supported by your OS', status);
});
console.log("Button was pressed");
},
textFieldValue: "",
});
return viewModel;
}
module.exports = HomeViewModel;
Question 1
Repo clearly says "iOS Background Fetch API Implementation for NativeScript". However, in the code there are fallbacks for Android. So does it work an Android as good as on iOS? If that's the case, why specify OS/iOS in the repo title?
Question 2
Will this plugin continue to be supported in the future? I want to have a sustainable app as possible :)
Cheers.
I tried to restart background-fetch again removing comment in
BackgroundFetch.start(() => { ...
}, (status) { ...});
but syntax error occurs. I just fix it with (status) => but runtime error occurs with above message.
When I try to enable headless mode on Android 8.1 / Nexus 6P, I get an error java.lang.ClassNotFoundException
. We are running the latest version of NativeScript and the latest available version of your plugin. Not sure if relevant, but we're also using your background geolocation plugin.
BackgroundFetch.registerHeadlessTask(async () => {
console.log('[My BackgroundFetch HeadlessTask] onFetch');
// Do some asynchronous work (eg: HTTP Request)
// Politely signal to the OS that our processing is complete.
BackgroundFetch.finish();
});
// Configure Background Fetch
BackgroundFetch.configure({
stopOnTerminate: false,
startOnBoot: true,
enableHeadless: true
}, () => {
console.log("[js] BackgroundFetch event received");
// do stuff
console.log("[js] BackgroundFetch event completed");
}, (status) => {
console.log('BackgroundFetch not supported by your OS', status);
});
This is the log of the error:
System.err: java.lang.ClassNotFoundException: com.transistorsoft.backgroundfetch.HeadlessJobService
System.err: at java.lang.Class.classForName(Native Method)
System.err: at java.lang.Class.forName(Class.java:453)
System.err: at java.lang.Class.forName(Class.java:378)
System.err: at com.transistorsoft.tsbackgroundfetch.BackgroundFetch.onFetch(BackgroundFetch.java:176)
System.err: at com.transistorsoft.tsbackgroundfetch.BackgroundFetch.onFetch(BackgroundFetch.java:151)
System.err: at com.transistorsoft.tsbackgroundfetch.FetchJobService.onStartJob(FetchJobService.java:22)
System.err: at android.app.job.JobService$1.onStartJob(JobService.java:71)
System.err: at android.app.job.JobServiceEngine$JobHandler.handleMessage(JobServiceEngine.java:108)
System.err: at android.os.Handler.dispatchMessage(Handler.java:106)
System.err: at android.os.Looper.loop(Looper.java:164)
System.err: at android.app.ActivityThread.main(ActivityThread.java:6494)
System.err: at java.lang.reflect.Method.invoke(Native Method)
System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
System.err: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.transistorsoft.backgroundfetch.HeadlessJobService" on path: DexPathList[[zip file "/data/app/com.test.app-hFj8-9wq6p-ke3BOsoW15Q==/base.apk"],nativeLibraryDirectories=[/data/app/com.test.app-hFj8-9wq6p-ke3BOsoW15Q==/lib/arm, /data/app/com.test.app-hFj8-9wq6p-ke3BOsoW15Q==/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
System.err: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
System.err: ... 14 more
Any ideas? A full re-build didn't help.
Plugin version: 1.2.0
Platform: Android
OS version: API VERSION 24
Device manufacturer / model: Emulator (Nexus 5)
Plugin config:
...
import { BackgroundFetch } from "nativescript-background-fetch"
...
BackgroundFetch.configure({
minimumFetchInterval: 15, // minutes
stopOnTerminate: false,
startOnBoot: true,
enableHeadless: true,
}, () => {
console.log("[js] BackgroundFetch event received")
console.log(BackgroundFetch.headlessTask)
BackgroundFetch.finish(BackgroundFetch.FETCH_RESULT_NEW_DATA)
}, status => console.log('BackgroundFetch not supported by your OS', status))
BackgroundFetch.start(() => {
console.log("BackgroundFetch successfully started")
}, (status) => {
console.log("BackgroundFetch failed to start: ", status)
})
if (app.android) {
const cb = async () => {
console.log('[My BackgroundFetch HeadlessTask] onFetch')
BackgroundFetch.finish()
}
BackgroundFetch.registerHeadlessTask(cb)
console.log(BackgroundFetch.headlessTask)
console.log("HeadlessTask registered")
}
Hi guys, firtly thanks for the pluging it's awesome.
I just want to know if I'm doing something wrong here.
I'm running the code showed above and awayays when I run the command:
adb shell cmd jobscheduler run -f <your.application.id> 999
or even:
adb shell am broadcast -a <your.application.id>.event.BACKGROUND_FETCH
I'm getting that I have not defined my headlessTask.
'[BackgroundFetch] invokeHeadlessTask ERROR - headlessTask is null. Did you BackgroundFetch.registerHeadlessTask(myTask) in your app.ts?'
I'm not really sure what to do here, I've even put a log just before call the bit of code and my this.headlessTask is really undefined.
Looks like it's creating another intance of the class and losing the content for the this.headlessTask property.
Does anyone had a similar problem yet?
Thank you,
Denis
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.