自从我升级到React Native 0.30后,我的物理iPhone上的构建从预先捆绑的文件而不是开发服务器加载.查看更改的唯一方法是再次构建和运行应用程序.以前,我可以通过刷新立即在iPhone上看到更改.
如果我使用模拟器,那么从开发服务器更改负载就好了.
这是我的AppDelegate.m:
#import "AppDelegate.h"
#import "RCTBundleURLProvider.h"
#import "RCTRootView.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"upool"
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
Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的React Native项目,我正努力工作.这是一个iOS项目,它只是将一个RCTRootView添加到UIViewController中.当我从网络浏览器点击网址时,我得到:
Unable to resolve module `/src/components/HelloReact` from `/Users/myusername/Desktop/DemoReact/index.ios.js`: Directory /src/components/HelloReact doesn't exist.
Run Code Online (Sandbox Code Playgroud)
index.ios.js
'use strict';
import { AppRegistry } from 'react-native';
import HelloReact from '/src/components/HelloReact';
AppRegistry.registerComponent('HelloReact', () => HelloReact);
Run Code Online (Sandbox Code Playgroud)
HelloReact.js
import React, { Component } from 'react';
import { AppRegistry, Text } from 'react-native';
export default class HelloReact extends Component {
render() {
return (
<Text style={{fontWeight: 'bold'}}>
I am bold
<Text style={{color: 'red'}}>
and red
</Text>
</Text>
)
}
}
Run Code Online (Sandbox Code Playgroud)
我对如何解决这个问题感到茫然.我尝试了以下所有方法:
npm startnpm start --reset-cache