-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
79 lines (70 loc) · 2.45 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import React from 'react';
import { YellowBox, View, Text, Platform } from 'react-native';
// 1. Import the modules.
import BackgroundFetch from 'react-native-background-fetch';
import PushNotification from 'react-native-push-notification';
export default class App extends React.PureComponent {
constructor(props) {
super(props);
YellowBox.ignoreWarnings(['Warning:']);//ignore yellow box messages that starts with "Wraning:"
console.disableYellowBox = true;
//scheduleNextPrayer();
//backgroundServiceForAlarams();
}
componentDidMount = async () => {
// Push notifications setup (recommend extracting into separate file)
PushNotification.configure({
// onNotification is called when a notification is to be emitted
onNotification: notification => console.log(notification),
// Permissions to register for iOS
permissions: {
alert: true,
badge: true,
sound: true,
},
popInitialNotification: true,
requestPermissions: Platform.OS === 'ios'
});
// Background fetch setup (recommend extracting into separate file)
BackgroundFetch.configure(
{
minimumFetchInterval: 20, // fetch interval in minutes
forceAlarmManager: true, // <-- Set true to bypass JobScheduler.
stopOnTerminate: false,
enableHeadless:true,
startOnBoot: true,
requiredNetworkType: BackgroundFetch.NETWORK_TYPE_ANY, // Default
requiresCharging: false, // Default
requiresDeviceIdle: false, // Default
requiresBatteryNotLow: false, // Default
requiresStorageNotLow: false, // Default
},
async taskId => {
console.log('Received background-fetch event: ', taskId);
//alert("I was called");
// 3. Insert code you want to run in the background, for example:
const result = await awaitableResult();
if (result) {
// 4. Send a push notification
PushNotification.localNotification({
title: 'Test',
message: 'Test',
playSound: true,
soundName: 'default',
});
}
// Call finish upon completion of the background task
BackgroundFetch.finish(taskId);
},
error => {
console.error('RNBackgroundFetch failed to start.');
},
);
}
render() {
return (<View><Text>Hello</Text></View>);
}
}
export const awaitableResult = () => {
return Promise.resolve(true);
};