forked from mathias5r/rn-heartbeat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
71 lines (64 loc) · 2.04 KB
/
index.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
import * as axios from 'axios';
import React from 'react';
import { AppRegistry } from 'react-native';
import { check, PERMISSIONS, request, RESULTS } from 'react-native-permissions';
import SendSMS from 'react-native-sms-x';
import { Provider } from 'react-redux';
import App from './App';
import { name as appName } from './app.json';
import { store } from './store';
const MyHeadlessTask = async (store) => {
console.log('State: ', store.getState());
const { App } = store.getState();
const { phoneNumber } = App;
console.log('Sending SMS to: ' + phoneNumber);
axios
.get('http://dummy.restapiexample.com/api/v1/employees')
.then((res) => {
console.log(res.data.status, res.data.data.length);
check(PERMISSIONS.ANDROID.SEND_SMS)
.then((result) => {
const sensSMS = () =>
SendSMS.send(
123,
phoneNumber,
`${res.data.status}: ${res.data.data.length}`,
(msg) => console.log(msg)
);
switch (result) {
case RESULTS.GRANTED:
sensSMS();
console.log(RESULTS.GRANTED);
break;
default:
request(PERMISSIONS.ANDROID.SEND_SMS)
.then((result) => {
switch (result) {
case RESULTS.GRANTED:
sensSMS();
break;
default:
console.log(
`Permission to send and read sms denied`,
result
);
break;
}
})
.catch((err) => console.error(err));
break;
}
})
.catch((err) => console.error(err));
})
.catch((err) => console.error(err));
};
const RNRedux = () => (
<Provider store={store}>
<App />
</Provider>
);
AppRegistry.registerHeadlessTask('Heartbeat', () =>
MyHeadlessTask.bind(null, store)
);
AppRegistry.registerComponent(appName, () => RNRedux);