Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static backgroundFetchAuthorizationStatus() {
BackgroundFetch.status(status => {
switch (status) {
case BackgroundFetch.STATUS_RESTRICTED:
console.log('BackgroundFetch restricted');
break;
case BackgroundFetch.STATUS_DENIED:
console.log('BackgroundFetch denied');
break;
case BackgroundFetch.STATUS_AVAILABLE:
console.log('BackgroundFetch is enabled');
break;
}
});
}
return new Promise(resolve => {
BackgroundFetch.status(status => {
if (status === BackgroundFetch.STATUS_RESTRICTED) {
return resolve({
available: false,
unavailableReason: 'restricted',
})
} else if (status === BackgroundFetch.STATUS_DENIED) {
return resolve({
available: false,
unavailableReason: 'denied',
})
}
return resolve({
available: true,
})
})
stopOnTerminate: false,
startOnBoot: true,
},
async () => {
await pushTracking('backgroundFetch', 'started')
await clearAndDownloadIssue()
await pushTracking('backgroundFetch', 'ended')
BackgroundFetch.finish(BackgroundFetch.FETCH_RESULT_NEW_DATA)
},
error => {
pushTracking('backgroundFetchError', error.toString())
},
)
const ID = 'backgroundFetchStatus'
BackgroundFetch.status(status => {
switch (status) {
case BackgroundFetch.STATUS_RESTRICTED:
pushTracking(ID, 'restricted')
break
case BackgroundFetch.STATUS_DENIED:
pushTracking(ID, 'denied')
break
case BackgroundFetch.STATUS_AVAILABLE:
pushTracking(ID, 'enabled')
break
}
})
}