Repository navigation
Expand file tree
/
Copy pathOneSignal.js
More file actions
122 lines (111 loc) · 3.42 KB
/
Copy pathOneSignal.js
File metadata and controls
122 lines (111 loc) · 3.42 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import React, { Component } from 'react';
import {
StyleSheet, Text, View, TouchableOpacity,
} from 'react-native';
import { GoogleSignin } from 'react-native-google-signin';
import OneSignal from 'react-native-onesignal';
import FBSDK, { LoginManager, AccessToken, LoginButton } from 'react-native-fbsdk';
const { GraphRequest, GraphRequestManager } = FBSDK;
export default class App extends Component {
componentDidMount() {
OneSignal.init('1dd5d2bd-e17a-45a3-9d86-ec38d4b725e7');
OneSignal.setSubscription(true);
OneSignal.inFocusDisplaying(2);
OneSignal.addEventListener('received', this.onReceived);
OneSignal.addEventListener('opened', this.onOpened);
OneSignal.addEventListener('ids', this.onIds);
}
onReceived = (notification) => {
console.log('Notification received: ', notification);
};
onOpened = (openResult) => {
console.log('Message: ', openResult.notification.payload.body);
console.log('Data: ', openResult.notification.payload.additionalData);
console.log('isActive: ', openResult.notification.isAppInFocus);
console.log('openResult: ', openResult);
};
onIds = (device) => {
console.log('Device info: ', device);
};
_signInGoogle = () => {
GoogleSignin.signIn()
.then((user) => {
console.log(user);
})
.catch((err) => {
console.log('err', err.code);
})
.done();
};
_getInfoFb = async () => {
const data = await AccessToken.getCurrentAccessToken();
const infoRequest = new GraphRequest(
'/me',
{
parameters: {
fields: {
string: 'email,name,location,birthday,photos', // what you want to get
},
access_token: {
string: data.accessToken, // put your accessToken here
},
},
},
this._responseInfoCallback,
);
new GraphRequestManager().addRequest(infoRequest).start();
};
_responseInfoCallback = (err, result) => {
console.log(err);
console.log(result);
};
_signInFacebook = () => {
LoginManager.logOut();
LoginManager.logInWithReadPermissions(['public_profile'])
.then((res) => {
this._getInfoFb();
})
.catch((err) => {
console.log(err);
});
};
render() {
return (
<View style={styles.container}>
<TouchableOpacity style={{ backgroundColor: 'silver' }} onPress={this._signInGoogle}>
<Text style={{ margin: 10 }}>login google</Text>
</TouchableOpacity>
<TouchableOpacity
style={{ backgroundColor: 'silver', margin: 10 }}
onPress={this._signInFacebook}
>
<Text style={{ margin: 10 }}>facebook</Text>
</TouchableOpacity>
<View>
<LoginButton
onLoginFinished={(error, result) => {
if (error) {
console.log(`login has error: ${result.error}`);
} else if (result.isCancelled) {
console.log('login is cancelled.');
} else {
AccessToken.getCurrentAccessToken().then((data) => {
console.log(data.accessToken.toString());
});
}
}}
onLogoutFinished={() => console.log('logout.')}
/>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
});