reactnativecn / react-native-pushy

React Native 极速热更新服务
https://pushy.reactnative.cn
Other
1.77k stars 257 forks source link

useAlert 设置false之后,仍然会弹出系统默认的alert页面提示热更 #438

Closed AllenPan03 closed 4 months ago

AllenPan03 commented 4 months ago

react-native-update版本:10.5.4 rn版本:0.70.1 安卓版本:HarmonyOS 3.0.0

三个问题: 问题一:useAlert 设置false之后,仍然会弹出系统默认的alert页面提示热更 问题二:控制台切换绑定的版本号之后,重启也无法自动更新,需要手机端删除数据和清空缓存才行 问题三:我想通过代码实现静默更新,但发现没有效果,代码如下:

import { useEffect } from 'react'
import { StatusBar } from 'react-native'
import { PushyProvider, Pushy, usePushy } from "react-native-update";

const pushyClient = new Pushy({
  appKey: "xxxx",
  // 注意,默认情况下,在开发环境中不会检查更新
  // 如需在开发环境中调试更新,请设置debug为true
  useAlert: false,
  // debug: true,
});

const App = ({ children }) => {
  const {
    checkUpdate,
    switchVersionLater,
    downloadUpdate
  } = usePushy();
  useEffect(() => {
    hotUpdate();
  }, []);

  const hotUpdate = async () => {
    try {
      const updateInfo: any = await checkUpdate();
      console.log("🚀 ~ hotUpdate ~ updateInfo:", updateInfo)
      if (updateInfo?.update) {
        await downloadUpdate();
        switchVersionLater();
      }
    } catch (e) {
      console.error("🚀 ~ hotUpdate ~ e", e)
    }

  }

  return <>
    <StatusBar
      translucent
      backgroundColor="rgba(0, 0, 0, 0)"
      barStyle="dark-content"
    />
    <PushyProvider client={pushyClient}>
      {children}
    </PushyProvider>
  </>
}

export default App
sunnylqm commented 4 months ago
  1. 使用provider的当前组件是不能获得其context的,因此也无法正常调用usePushy方法。必须在子组件中使用。所有基于context/provider的hook,都是只能在子组件中使用。
  2. updateInfo是usePushy返回的,并不是checkUpdate方法返回的
  3. 其他问题建议加qq 34731408交流