将react本机组件添加到本机ios应用程序时,在设备上运行时始终无法连接到服务器
我正在尝试将react native组件添加到本机ios应用程序。我可以在模拟器上成功运行,但在设备上运行时,总是显示红色错误:无法连接到服务器 我的应用程序结构如下: ReactViewController是加载react本机组件的视图控制器将react本机组件添加到本机ios应用程序时,在设备上运行时始终无法连接到服务器,ios,react-native,Ios,React Native,我正在尝试将react native组件添加到本机ios应用程序。我可以在模拟器上成功运行,但在设备上运行时,总是显示红色错误:无法连接到服务器 我的应用程序结构如下: ReactViewController是加载react本机组件的视图控制器 - (void)viewDidLoad { [super viewDidLoad]; NSURL *jsCodeLocation; #if DEBUG NSLog(@"AppDelegate:DEBUG"); #if T
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *jsCodeLocation;
#if DEBUG
NSLog(@"AppDelegate:DEBUG");
#if TARGET_IPHONE_SIMULATOR
NSLog(@"AppDelegate:DEBUG:TARGET_IPHONE_SIMULATOR");
jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle"];
#else
NSLog(@"AppDelegate:DEBUG:!TARGET_IPHONE_SIMULATOR");
NSLog(@"To device debug, open RCTWebSocketExecutor.m & replace localhost with MacBook IP.");
// Get dev host IP Address:
// ifconfig | grep inet\ | tail -1 | cut -d " " -f 2
jsCodeLocation = [NSURL URLWithString:@"http://19.244.52.152:8081/ReactComponent/index.ios.bundle"];
#endif
#else
NSLog(@"AppDelegate:RELEASE jsbundle");
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
RCTRootView * rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"FPDemo"
initialProperties:nil
launchOptions:nil];
self.view = rootView;
}
您是否也在iOS 9.0+Apple中编辑了默认阻止非安全(http)请求的RCTWebSocketExecutor.m。您必须将其添加到Info.plist
NSAppTransportSecurity NSExceptionDomains localhost NSTemporaryExceptionAllowsInsecureHTTPLoads
中,或者不允许您使用特定的IP地址,您可以禁用NSAppTransportSecurity
功能NSAppTransportSecurity NSAllowsArbitraryLoads
你应该看看@Ashok,我尝试了你的建议,但还是失败了。