checkVersion.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import Constants from 'expo-constants';
  2. import * as Linking from 'expo-linking';
  3. import { Alert, Platform, BackHandler } from 'react-native';
  4. // import * as Updates from 'expo-updates';
  5. export function checkVersion(fetchedVersion: { version: string; isActive: boolean }) {
  6. const currentVersion = Constants.expoConfig?.version;
  7. // console.log('currentVersion', currentVersion);
  8. console.log('fetchedVersion', fetchedVersion.version);
  9. console.log('fetchedVersion.isActive', fetchedVersion.isActive);
  10. if (!fetchedVersion.isActive) {
  11. Alert.alert(
  12. '伺服器維護中,敬請見諒',
  13. '',
  14. [
  15. {
  16. text: '確認',
  17. onPress: () => {
  18. if (Platform.OS === 'android') {
  19. BackHandler.exitApp();
  20. } else {
  21. return;
  22. }
  23. }
  24. }
  25. ],
  26. { cancelable: false }
  27. );
  28. // Prevent any further code execution
  29. throw new Error('MAINTENANCE_MODE');
  30. }
  31. // if (currentVersion && currentVersion !== '1.2.9') {
  32. if (currentVersion && currentVersion !== fetchedVersion.version) {
  33. Alert.alert(
  34. '請更新到最新版本',
  35. 'Please update to the latest version of the app to continue.',
  36. [
  37. {
  38. text: '現在更新',
  39. onPress: () => {
  40. const url =
  41. Platform.OS === 'ios'
  42. ? 'https://apps.apple.com/app/crazy-charge/id6639612402'
  43. : 'https://play.google.com/store/apps/details?id=hk.com.crazycharge';
  44. Linking.openURL(url);
  45. }
  46. }
  47. ],
  48. { cancelable: false }
  49. );
  50. }
  51. }