38 lines
No EOL
953 B
TypeScript
38 lines
No EOL
953 B
TypeScript
import React, { useEffect } from 'react';
|
|
import * as Updates from 'expo-updates';
|
|
import { Alert } from 'react-native';
|
|
|
|
interface UpdateCheckerProps {
|
|
children: React.ReactNode;
|
|
}
|
|
|
|
const UpdateChecker: React.FC<UpdateCheckerProps> = ({ children }) => {
|
|
useEffect(() => {
|
|
const checkForUpdates = async () => {
|
|
try {
|
|
const update = await Updates.checkForUpdateAsync();
|
|
if (update.isAvailable) {
|
|
Alert.alert(
|
|
"Update available",
|
|
"Restart app to apply the update?",
|
|
[
|
|
{ text: "Later", style: "cancel" },
|
|
{ text: "Restart", onPress: () => Updates.reloadAsync() }
|
|
]
|
|
);
|
|
}
|
|
} catch (error) {
|
|
console.log('Update check failed:', error);
|
|
}
|
|
};
|
|
|
|
// Only check on production builds
|
|
if (!__DEV__) {
|
|
checkForUpdates();
|
|
}
|
|
}, []);
|
|
|
|
return <>{children}</>;
|
|
};
|
|
|
|
export default UpdateChecker; |