react-native环境搭建遇阻

按照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**
不知路在何方,求大神们指点一二,不胜感激,跪谢

阅读 2.5k
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题