Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将react本机组件添加到本机ios应用程序时,在设备上运行时始终无法连接到服务器_Ios_React Native - Fatal编程技术网

将react本机组件添加到本机ios应用程序时,在设备上运行时始终无法连接到服务器

将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

我正在尝试将react native组件添加到本机ios应用程序。我可以在模拟器上成功运行,但在设备上运行时,总是显示红色错误:无法连接到服务器

我的应用程序结构如下:

ReactViewController是加载react本机组件的视图控制器

- (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,我尝试了你的建议,但还是失败了。