Packager can't listen on port 8081
You can configure the packager to use a port other than 8081 by using theportparameter:
$ react-native start --port=8088
You will also need to update your applications to load the JavaScript bundle from the new port.
To change the port used by an iOS application, edit the AppDelegate.m file in the ios folder. Scroll down to the line where the bundle location is defined, and replace 8081 with the new port.
js CodeLocation=[NSURL URLWithString:@"http://localhost:8088/index.ios.bundle"];
若上面二种方式不好使,可以采用如下方式
1.在React Native项目根目录下运行 npm start
2.使用curl命令生成 main.jsbundle
curlhttp://localhost:8081/index.ios.bundle -o main.jsbundle
3.在AppDelegate.m中选择使用main.jsbundle注释掉
jsCodeLocation= [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];
修改8081端口号即可
网友评论