应用尚未注册(react-native-navigation v2)

Posted

技术标签:

【中文标题】应用尚未注册(react-native-navigation v2)【英文标题】:Application has not been registered (react-native-navigation v2) 【发布时间】:2018-11-13 23:35:24 【问题描述】:

React 原生导航 v2 问题。

我的应用程序以 index.js 开头,并且也注册到 AppDelegate 中。详情如下:

import AppRegistry from 'react-native'; const start = require('./src/app'); start();

这里是 app.js:

```

const  Navigation  = require('react-native-navigation');
const  registerScreens  = require('./screens');
const  Platform  = require('react-native');

if (Platform.OS === 'android') 
alert = (title) => 
    Navigation.showOverlay(
        component: 
            name: 'navigation.playground.alert',
            passProps: 
                title
            ,
            options: 
                overlay: 
                    interceptTouchOutside: true
                
            
        
    );
;


function start() 
registerScreens();
Navigation.events().registerAppLaunchedListener(() => 
    Navigation.setDefaultOptions(
        _animations: 
            startApp: 
                y: 
                    from: 1000,
                    to: 0,
                    duration: 500,
                    interpolation: 'accelerate',
                ,
                alpha: 
                    from: 0,
                    to: 1,
                    duration: 500,
                    interpolation: 'accelerate'
                
            ,
            push: 
                topBar: 
                    id: 'TEST',
                    alpha: 
                        from: 0,
                        to: 1,
                        duration: 500,
                        interpolation: 'accelerate'
                    
                ,
                bottomTabs: 
                    y: 
                        from: 1000,
                        to: 0,
                        duration: 500,
                        interpolation: 'decelerate',
                    ,
                    alpha: 
                        from: 0,
                        to: 1,
                        duration: 500,
                        interpolation: 'decelerate'
                    
                ,
                bottomTabs: 
                    y: 
                        from: 1000,
                        to: 0,
                        duration: 500,
                        interpolation: 'decelerate',
                    ,
                    alpha: 
                        from: 0,
                        to: 1,
                        duration: 500,
                        interpolation: 'decelerate'
                    
                ,
                content: 
                    y: 
                        from: 1000,
                        to: 0,
                        duration: 500,
                        interpolation: 'accelerate',
                    ,
                    alpha: 
                        from: 0,
                        to: 1,
                        duration: 500,
                        interpolation: 'accelerate'
                    
                
            ,
            pop: 
                topBar: 
                    id: 'TEST',
                    alpha: 
                        from: 1,
                        to: 0,
                        duration: 500,
                        interpolation: 'accelerate'
                    
                ,
                bottomTabs: 
                    y: 
                        from: 0,
                        to: 100,
                        duration: 500,
                        interpolation: 'accelerate',
                    ,
                    alpha: 
                        from: 1,
                        to: 0,
                        duration: 500,
                        interpolation: 'accelerate'
                    
                ,
                bottomTabs: 
                    y: 
                        from: 0,
                        to: 100,
                        duration: 500,
                        interpolation: 'decelerate',
                    ,
                    alpha: 
                        from: 1,
                        to: 0,
                        duration: 500,
                        interpolation: 'decelerate'
                    
                ,
                content: 
                    y: 
                        from: 0,
                        to: 1000,
                        duration: 500,
                        interpolation: 'decelerate',
                    ,
                    alpha: 
                        from: 1,
                        to: 0,
                        duration: 500,
                        interpolation: 'decelerate'
                    
                
            
        
    );

    Navigation.setRoot(
        root: 
            stack: 
                id: 'TEST',
                children: [
                    
                        component: 
                            name: 'rp.welcome'
                        
                    
                ]
            
        
    );
);



module.exports = 
  start
;

屏幕注册:

const  Navigation  = require('react-native-navigation');
const WelcomeScreen = require('./WelcomeScreen');
const Authentication = require('./Authentication').default;
const Tutorial = require('./Tutorial');

function registerScreens() 
Navigation.registerComponent(`rp.welcome`, () => WelcomeScreen);
Navigation.registerComponent(`rp.tutorial`, ()=>Tutorial);
Navigation.registerComponent(`rp.authentication.super`,()=> Authentication);


module.exports = 
 registerScreens
 ;

环境:

"dependencies": 
"react": "16.3.1",
"react-native": "0.55.4",
"react-native-navigation": "^2.0.2314",
"react-native-video": "^2.1.1",
"rn-viewpager": "^1.2.9"
 ,

【问题讨论】:

【参考方案1】:

我已经通过这样放置组件的字符串名称来解决这个问题:

而不是:component: YourComponent

应该是:

component: 
   name: 'YourComponent'

完整代码如下:

Navigation.events().registerAppLaunchedListener(() => 
    Navigation.setRoot(
        root: 
            stack: 
                children: [
                    
                        component:                             
                            name: 'YourComponent'
                        
                    
                ]
            
        
    )
);

另外,如果你 push 或 setStackRoot,你应该总是使用组件名: 例如

component: 
name: 'YourComponent'

【讨论】:

【参考方案2】:

我在 V2 中遇到过类似的问题,问题是由于没有删除 AppDelegate.m 中 didFinishLaunchingWithOptions 方法中的 rootView 设置。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions


  NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
  [ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions];


  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"XXXXXXXXXX"
                                               initialProperties:nil
                                                   launchOptions:launchOptions];
  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];

  return YES;

如果你把它们留在里面,会导致应用程序 XXXXXXXXXX 未注册错误。 https://wix.github.io/react-native-navigation/v2/#/docs/Installing中的ios指令应该强调这些rootView相关的行一定要去掉。

正确的 AppDelegates.m 应该是这样的:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions


  NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
  [ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions];

  return YES;

【讨论】:

我不得不说这是我的问题的实际答案。我在网上到处查看每个问题,我很高兴这个答案甚至存在。感谢 RedGiant,我希望其他人也会因为自己的心理原因而偶然发现这一点【参考方案3】:

我遇到了同样的问题,但只在 Android 上。原来我错过了配置过程中的一步。

在 MainActivity.java 中它应该扩展 com.reactnativenavigation.NavigationActivity 而不是 ReactActivity。

https://wix.github.io/react-native-navigation/v2/#/docs/Installing.

【讨论】:

在我的情况下不起作用,并且找不到您提供的链接

以上是关于应用尚未注册(react-native-navigation v2)的主要内容,如果未能解决你的问题,请参考以下文章

Wix React-Native-Navigation v2 和 redux-persist

使用 wix@react-native-navigation 运行 react-native 应用程序时出错

运行时错误:应用程序注册表尚未准备好

如何判断推送通知是尚未注册还是已关闭?

Django ForeignKey 默认 - 应用程序注册表尚未准备好

ASP.NET 4.0尚未在 Web 服务器上注册 解决方法