按照react-native中文网的教程在mac上搭建react-native的环境
react-native init AwesomeProject
cd AwesomeProject
react-native run-ios
做到了这步
提示如下
Connection to localhost port 8081 [tcp/sunproxyadmin] succeeded!
**Port 8081 already in use, packager is either not running or not running correctly
Command /bin/sh failed with exit code 2**
网上找到的方案是在 AppDelegate.m 中,
Change
http://localhost:8081/index.ios.bundle?platform=ios&dev=true
to
http://localhost:8999/index.ios.bundle?platform=ios&dev=true
#import "AppDelegate.h"
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"AwesomeProject"
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;
}
@end
我的AppDelegate.m如上
但并没有找到 http://....8081
执行了另一个回答中的方案sudo lsof -n -i4TCP:8081
依然还是**Port 8081 already in use, packager is either not running or not running correctly
Command /bin/sh failed with exit code 2**
不知路在何方,求大神们指点一二,不胜感激,跪谢
我也是这个问题,init的0.44.3版本react-native。改了server的port,代码里的8081也都改了,报错还是跟上面一样8081.请问你解决了吗