在oc中写rn 代码

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

NSURL * jsCodeLocation = [NSURL URLWithString:@"http://127.0.0.1:8081/index.ios.bundle?platform=ios&dev=true"];

RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation

moduleName:@"HelloWorldApp"

initialProperties:nil

launchOptions:nil];

rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

CGRect rect=CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width , [UIScreen mainScreen].bounds.size.height);

self.window = [[UIWindow alloc] initWithFrame:rect];

UIViewController *rootViewController = [UIViewController new];

rootViewController.view = rootView;

self.window.rootViewController=rootViewController;

[self.window makeKeyAndVisible];

return YES;

}

由于没有开启服务 运行报错Could not connect to development server

解决方法 

(1)终端cd到当前项目 然后npm start 然后重新运行xcode项目,还是报错的话就退出xcode 重新来一次就ok了

你可能感兴趣的:(在oc中写rn 代码)