1

我正在尝试将 App Clip 功能集成到我开发的应用程序中,该应用程序是与 EXPO 进行本机反应的。

我声明我已经在没有 EXPO 的 React Native 项目中集成了 App Clip 功能,并且我没有遇到任何重大问题,而使用 expo 我有一个我无法解决的问题。

我在 main.m 文件中收到此错误:

不变违规:“ReactNativeTest”尚未注册。在以下情况下可能会发生这种情况:

  • Metro(本地开发服务器)从错误的文件夹运行。检查 Metro 是否正在运行,将其停止并在当前项目中重新启动。
  • 一个模块由于错误而未能加载并且AppRegistry.registerComponent未被调用。

我相信这个问题与 ViewController.m 文件有关:

// moduleName corresponds to the appName used for the
// app entry point in "index.js"
RCTRootView *rootView = [[RCTRootView alloc]
initWithBundleURL:jsCodeLocation moduleName:@"ReactNativeTest"
initialProperties:nil launchOptions:nil];

在没有 EXPO 的项目中,“index.js”中应用程序入口点的模块名称是这样的

在此处输入图像描述

但在这种情况下它不起作用,你有解决方案吗?

4

1 回答 1

1

好的,我自己找到了解决方案,如果有人需要,我按照以下步骤操作:

在 index.appclip.js 中,我对此进行了修改:

import { AppRegistry, View, Text } from 'react-native';
import { name as appName } from './app.json';
import React from 'react';

const AppClip = () => (
  <View style={{
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "#BFEFFF"
  }}>
    <Text style={{
      fontSize: 26,
      color: "#204080"
    }}>Hello React Native App Clip</Text>
  </View>
);

AppRegistry.registerComponent(appName, () => AppClip);

对此:

import { View, Text } from 'react-native';
import { registerRootComponent } from 'expo';
import React from 'react';

const AppClip = () => (
  <View style={{
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "#BFEFFF"
  }}>
    <Text style={{
      fontSize: 26,
      color: "#204080"
    }}>Hello React Native App Clip</Text>
  </View>
);

registerRootComponent(AppClip);

并且“index.js”中应用程序入口点的模块名称是“main”,所以我修改了 ViewController.m,如下所示:

// moduleName corresponds to the appName used for the
// app entry point in "index.js"
RCTRootView *rootView = [[RCTRootView alloc]
initWithBundleURL:jsCodeLocation moduleName:@"main"
initialProperties:nil launchOptions:nil];
于 2021-07-02T15:07:28.853 回答