-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
95 lines (84 loc) · 2.85 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
import { useState, useEffect } from 'react';
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View, Button } from 'react-native';
import * as Updates from 'expo-updates';
/*
FROM SDK50
import { useUpdates } from 'expo-updates';
export default function App() {
const {
currentlyRunning,
availableUpdate,
isUpdateAvailable,
isUpdatePending,
// and so on!
} = useUpdates();
// etc..
}
*/
export default function App() {
const onPress = async () => {
try {
const update = await Updates.checkForUpdateAsync();
console.log('checkForUpdateAsync() : ' + JSON.stringify(update));
if (update.isAvailable) {
const fetchResult = Updates.fetchUpdateAsync(); // Downloads the most recently deployed update to your project from server to the device's local storage. This method cannot be used in development mode, and the returned promise will be rejected if you try to do so
console.log('fetchUpdateAsync() : ' + JSON.stringify(fetchResult));
if (fetchResult.isNew) {
Updates.reloadAsync(); // Instructs the app to reload using the most recently downloaded version
}
}
} catch (error) {
console.log('ERROR : ' + error.message);
}
};
function printConstants() {
// Constants
console.log('***********************');
console.log('channel : ' + Updates.channel);
console.log('createdAt : ' + Updates.createdAt);
console.log('isEmbeddedLaunch : ' + Updates.isEmbeddedLaunch);
console.log('isEmergencyLaunch : ' + Updates.isEmergencyLaunch);
console.log('manifest : ' + JSON.stringify(Updates.manifest));
console.log('releaseChannel : ' + Updates.releaseChannel);
console.log('runtimeVersion : ' + Updates.runtimeVersion);
console.log('updateId : ' + Updates.updateId);
console.log('***********************');
}
const eventListener = (event) => {
if (event.type === Updates.UpdateEventType.ERROR) {
// Handle error
console.log('error');
} else if (event.type === Updates.UpdateEventType.NO_UPDATE_AVAILABLE) {
// Handle no update available
console.log('No update available');
} else if (event.type === Updates.UpdateEventType.UPDATE_AVAILABLE) {
// Handle update available
console.log('Update available');
}
};
Updates.useUpdateEvents(eventListener); // React hook to create an UpdateEvent listener subscription on mount, using addListener. It calls remove() on the subscription during unmount.
useEffect(() => {
printConstants();
}, []);
return (
<View style={styles.container}>
<Text>Open up App.js to start working on your app!</Text>
<Button
onPress={onPress}
title="Press me"
color="#841584"
accessibilityLabel="Learn more about this purple button"
/>
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});