0

我已经坚持了两天了,即使有人问过这个问题。没有一个答案对我有帮助。

我正在使用 Wix Navigation V2 并尝试使用 CodePush 进行即时更新。在 staging 中,我可以看到 CodePush 日志和更新发生(只是检查以查看日志)。然而,在生产中,我的应用程序总是在启动后恢复为黑屏。这是我到目前为止所尝试的。

这种方法:https ://medium.com/react-coach/using-codepush-with-wix-react-native-navigation-a6a7938cee24

我还确保我的部署密钥在我的 plist 文件中是正确的 appcenter codepush deployment list -a {myUserName}/{appName} -k

我也尝试过这些方法 使用 Wix 的 React Native Navigation 注册 React Native Code Push

这是我的 App.js 代码

  TODO: 
  SET ORIENTATION
*/

import { NetInfo, Platform } from "react-native";
import { createStore, applyMiddleware } from "redux";
import { composeWithDevTools } from "redux-devtools-extension";
import { Provider } from "react-redux";
import thunk from "redux-thunk";
import { Navigation } from "react-native-navigation";
import codePush from "react-native-code-push";
import { registerScreens, registerScreenVisibilityListener } from "./screens";
import rootReducer from "./redux/reducers/index";
import { connectionStatusChanged } from "./redux/actions";

const store = createStore(
  rootReducer,
  composeWithDevTools(applyMiddleware(thunk))
);

registerScreens(store, Provider);
registerScreenVisibilityListener();

const handleConnectivityChange = reach => {
  store.dispatch(connectionStatusChanged(reach));
};

NetInfo.addEventListener("connectionChange", handleConnectivityChange);

export default class App {
  constructor() {
    store.subscribe(this.onStoreUpdate.bind(this));

    NetInfo.getConnectionInfo().then(reach => {
      handleConnectivityChange(reach);
    });
  }

  onStoreUpdate = () => {
    const { appRoot } = store.getState().appState;

    if (this.currentRoot !== appRoot) {
      // CODE PUSH SYNC
      codePush.sync({
        updateDialog: true,
        installMode: codePush.InstallMode.IMMEDIATE
      });
      this.currentRoot = appRoot;
      this.startApp(appRoot);
    }
  };

  startApp = root => {
    // ALL MY RNN V2 SCREENS (REMOVING TO REDUCE CODE)
  } 

}

这是我注册屏幕并使用 codepush 包装 HOC 的地方

import React from "react";
import _ from "lodash";
import { Provider } from "react-redux";
import { Linking } from "react-native";
import { Navigation } from "react-native-navigation";
import codePush from "react-native-code-push";
import NavigationActions from "../navigation/navigationActions";


const codePushOptions = { checkFrequency: codePush.CheckFrequency.MANUAL };

function wrap(WrappedComponent, store) {
  class PP extends React.PureComponent {
    componentWillMount() {
      Linking.addEventListener("url", this.deeplinkHandler);
      Linking.getInitialURL().then(url => {
        // FUNCTION HERE TO ROUTE TO ARTICLE, STRAIN, PRODUCT (when ap is closed)

        if (url) {
          const linkData = url.replace("weedup://", "").split("/");
          if (this.props.componentId === "home" && linkData[0] === "article") {
            // push component
            const { componentId } = this.props;
            NavigationActions.pushComponent({
              id: "home",
              name: "screen.Article",
              props: {
                fromDeepLink: true,
                fromBackground: false,
                article: {
                  id: linkData[1]
                }
              },
              title: "Article",
              topBarVisible: true,
              bottomTabsVisible: false
            });
          }
        }
      });
    }

    deeplinkHandler = event => {
      // FUNCTION HERE TO ROUTE TO ARTICLE, STRAIN, PRODUCT (opened)
      if (!_.isEmpty(event)) {
        const linkData = event.url.replace("weedup://", "").split("/");
        if (this.props.componentId === "home" && linkData[0] === "article") {
          const { componentId } = this.props;
          NavigationActions.pushComponent({
            id: "home",
            name: "screen.Article",
            props: {
              fromDeepLink: true,
              fromBackground: true,
              article: {
                id: linkData[1]
              }
            },
            title: "Article",
            topBarVisible: true,
            bottomTabsVisible: false
          });
        }
      }
    };

    render() {
      return (
        <Provider store={store}>
          <WrappedComponent {...this.props} />
        </Provider>
      );
    }
  }

  return codePush(codePushOptions)(PP);
}

export const registerScreens = store => {
 // REMOVING SCREEN TO REDUCE EXAMPLE CODE
};

export function registerScreenVisibilityListener() {
  Navigation.events().registerComponentDidAppearListener(
    ({ componentName }) => {
      console.log(`Displaying screen ${componentName}`);
    }
  );
}

最后,这是我的 AppDelegate.m

 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

#import "AppDelegate.h"

#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "ReactNativeNavigation.h"
#import <React/RCTLinkingManager.h>

#import <CodePush/CodePush.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
  return [RCTLinkingManager application:application openURL:url
                      sourceApplication:sourceApplication annotation:annotation];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  NSURL *jsCodeLocation;

#ifdef DEBUG
  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
  [ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions];
#else
  jsCodeLocation = [CodePush bundleURL];
#endif


  return YES;
}

@end
4

2 回答 2

1

嘿,也许我迟到了,但是因为我在将 RNN 与 CodePush 集成时偶然发现了你的问题,所以我想我会把它放在这里。

看起来您不在 DEBUG 中时没有使用 RNN 所以我只需将您的didFinishLaunchingWithOptions函数替换为:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  NSURL *jsCodeLocation;

#ifdef DEBUG
  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  jsCodeLocation = [CodePush bundleURL];
#endif

  [ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions];

  return YES;
}
于 2019-09-27T09:10:43.170 回答
0

您还可以使用 Expo 实现热更新,这是一个带有 Expo 更新和 React Native 导航的工作示例。这个项目没有附加到 Expo CLI,所以你可以使用它的裸 React Native 项目

https://github.com/samithaf/expo-sample-app

于 2020-07-03T04:38:02.780 回答