【问题标题】:Get latest available version for user appstore and play market获取用户应用商店和游戏市场的最新可用版本
【发布时间】:2021-09-14 05:22:50
【问题描述】:

我有一些问题,我需要使用 react-native 检查当前用户的最新可用应用程序版本。我为 appstore 和 google play 市场的 20% 用户分阶段发布,但打包 react-native-version-check 向我发送所有用户的最新应用程序版本(一些用户应该获得可用版本,而不是最新版本)。如何获取用户可用的最新版本?

【问题讨论】:

    标签: react-native google-play app-store


    【解决方案1】:

    您可以使用 react-native-device-info 获取用户当前的应用版本,然后您可以使用 react-native-check-version 进行比较使用 AppStore 或 Play 商店版本。

    import { checkVersion, CheckVersionResponse } from "react-native-check-version";
    import DeviceInfo from 'react-native-device-info';
    
    // version update check
    const [version, setVersion]: [CheckVersionResponse | undefined, Dispatch<SetStateAction<CheckVersionResponse | undefined>>] = useState<CheckVersionResponse | undefined>(undefined)     
    const currentVersion: string = DeviceInfo.getVersion()
    
    async function checkV(): Promise<void> {
            const version = await checkVersion({
                currentVersion: currentVersion
            })
    
       setVersion(version)
    }
    
    useEffect(() => {
       checkV()
    }, [])
    

    【讨论】:

    • 感谢您的回答,但我如何检查当前用户是否可以使用最新版本(我使用分阶段发布,因此并非所有用户都能获得此版本)
    • 我认为如果有可用更新,此方法将为您的用户提供更新选项,因为用户将在 AppStore 中看到新版本,并且在用户设备上此方法会获取最新的可用版本。
    【解决方案2】:
    import VersionCheck from 'react-native-version-check';
    import {Linking } from 'react-native';
    
    versioncontrol = async () =>{
        VersionCheck.needUpdate()
        .then(async res => {
          if (res.isNeeded) {
           Linking.openURL(res.storeUrl)
        
          }else{
            console.log("Update Not Available")
        }).catch(error => {
         console.log(error)
        })
     
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-18
      • 2021-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多