问题描述:
我在编辑完一个项目的时候,新建了一个新的项目,然后执行react-native run-ios命令,结果出现如下错误:
Application XXX has not been registered. This is either due to a require() error during initialization or failure to call AppRegistry.registerComponent.
见下图:
解决办法:
参考:http://stackoverflow.com/questions/38340360/react-native-application-has-not-been-registered
首先,通过命令:ps aux | grep react-native 查看正在运行的进程,然后,找到launchPackager.command进程,再使用命令:kill加进程id 来结束该进程。
localhost:MyFirstRNProject hqtech$ ps aux | grep react-native
hqtech 13308 0.6 0.0 2461464 828 s003 S+ 5:08下午 0:00.01 grep react-native
hqtech 7817 0.1 0.3 3170480 21084 s004 S+ 12:48下午 4:03.43 node /Users/hqtech/AwesomeProject_android/node_modules/react-native/packager/../local-cli/cli.js start
hqtech 7812 0.0 0.0 2446696 348 s004 S+ 12:48下午 0:00.01 bash /Users/hqtech/AwesomeProject_android/node_modules/react-native/packager/launchPackager.command
localhost:MyFirstRNProject hqtech$ kill 7812
localhost:MyFirstRNProject hqtech$
localhost:MyFirstRNProject hqtech$
localhost:MyFirstRNProject hqtech$ ps aux | grep react-native
hqtech 7817 0.1 0.1 3170480 11412 ?? S 12:48下午 4:03.51 node /Users/hqtech/AwesomeProject_android/node_modules/react-native/packager/../local-cli/cli.js start
hqtech 13325 0.0 0.0 2453272 820 s003 S+ 5:09下午 0:00.01 grep react-native
localhost:MyFirstRNProject hqtech$
按上述步骤操作后,又出现了新的问题:
Could not connect to development server.
见下图:
这个问题的解决办法是:
打开:项目目录/ios/项目名/Info.plist 文件
在NSAppTransportSecurity下添加
<key>NSAppTransportSecurity</key>
<dict><key>NSAllowsArbitraryLoads</key><true/></dict>
再重新运行该项目,成功显示。