/
App.js
134 lines (116 loc) · 4.72 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
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
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { AppState, Alert, Platform, ToastAndroid, YellowBox } from 'react-native';
import { createBottomTabNavigator, createAppContainer } from 'react-navigation';
import Toast from 'react-native-simple-toast';
import Crashes, { UserConfirmation, ErrorAttachmentLog } from 'appcenter-crashes';
import Push from 'appcenter-push';
import Data from 'appcenter-data';
import AppCenterScreen from './screens/AppCenterScreen';
import TransmissionScreen from './screens/TransmissionScreen';
import AnalyticsScreen from './screens/AnalyticsScreen';
import CrashesScreen from './screens/CrashesScreen';
import DataScreen from './screens/DataScreen';
import AttachmentsProvider from './AttachmentsProvider';
YellowBox.ignoreWarnings(['Remote debugger']);
const TabNavigator = createBottomTabNavigator(
{
AppCenter: AppCenterScreen,
Analytics: AnalyticsScreen,
Transmission: TransmissionScreen,
Crashes: CrashesScreen,
Data: DataScreen
},
{
tabBarOptions: {
activeBackgroundColor: 'white',
inactiveBackgroundColor: 'white',
},
}
);
export default createAppContainer(TabNavigator);
Push.setListener({
onPushNotificationReceived(pushNotification) {
let message = pushNotification.message;
const title = pushNotification.title;
// Message can be null on iOS silent push or Android background notifications.
if (message === null) {
message = '';
} else {
message += '\n';
}
// Any custom name/value pairs added in the portal are in customProperties
if (pushNotification.customProperties && Object.keys(pushNotification.customProperties).length > 0) {
message += `Custom properties:\n${JSON.stringify(pushNotification.customProperties)}`;
}
if (AppState.currentState === 'active') {
Alert.alert(title, message);
} else {
// Sometimes the push callback is received shortly before the app is fully active in the foreground.
// In this case you'll want to save off the notification info and wait until the app is fully shown
// in the foreground before displaying any UI. You could use AppState.addEventListener to be notified
// when the app is fully in the foreground.
// Showing an alert when not in the "active" state seems to work on iOS; for Android, we show a toast
// message instead
if (Platform.OS === 'android') {
ToastAndroid.show(`Notification while inactive:\n${message}`, ToastAndroid.LONG);
}
Alert.alert(title, message);
}
}
});
Data.setRemoteOperationListener({
onRemoteOperationCompleted(document) {
console.log(`onRemoteOperationCompleted called in the delegate method. document id: ${document.id}`);
}
});
Crashes.setListener({
shouldProcess(report) {
console.log(`Should process report with id: ${report.id}'`);
return true;
},
shouldAwaitUserConfirmation() {
console.log('Should await user confirmation');
Alert.alert(
'One or more crashes were detected, do you want to report them?',
null,
[
{ text: 'Yes, and ask me again if it occurs again.', onPress: () => Crashes.notifyUserConfirmation(UserConfirmation.SEND) },
{ text: 'Yes, always send them', onPress: () => Crashes.notifyUserConfirmation(UserConfirmation.ALWAYS_SEND) },
{ text: 'Don\'t send at this time', onPress: () => Crashes.notifyUserConfirmation(UserConfirmation.DONT_SEND) },
]
);
return true;
},
getErrorAttachments(report) {
console.log(`Get error attachments for report with id: ${report.id}'`);
return (async () => {
const attachments = [];
const [textAttachment, binaryAttachment, binaryName, binaryType] = await Promise.all([
AttachmentsProvider.getTextAttachment(),
AttachmentsProvider.getBinaryAttachment(),
AttachmentsProvider.getBinaryName(),
AttachmentsProvider.getBinaryType(),
]);
if (textAttachment !== null) {
attachments.push(ErrorAttachmentLog.attachmentWithText(textAttachment, 'hello.txt'));
}
if (binaryAttachment !== null && binaryName !== null && binaryType !== null) {
attachments.push(ErrorAttachmentLog.attachmentWithBinary(binaryAttachment, binaryName, binaryType));
}
return attachments;
})();
},
onBeforeSending() {
console.log('Will send crash. onBeforeSending is invoked.');
Toast.show('Sending crashes...');
},
onSendingSucceeded() {
console.log('Did send crash. onSendingSucceeded is invoked.');
Toast.show('Sending crashes succeeded.');
},
onSendingFailed() {
console.log('Failed sending crash. onSendingFailed is invoked.');
Toast.show('Sending crashes failed, please check verbose logs.');
}
});