如何调试本机应用程序无法启动ios设备

时间:2016-08-08 09:10:13

标签: ios iphone debugging react-native

当我启动react-native应用程序时,它始终会启动,只要我将它连接到mac。

一旦断开iphone,应用程序大多会在启动和崩溃时挂起,而不会出现任何进一步的错误消息。 但是,其他错误将显示在屏幕上(红色和黄色标记的错误)。

当我双击家庭按钮时,奇怪的是,应用程序似乎处于启动状态,但我无法切换到它。

如何调试最佳此类行为并找到导致奇怪启动行为的事情?

更新

我发现了那些错误

2016-08-08 16:25:23.604 [warn][tid:main][RCTEventEmitter.m:54] Sending `websocketFailed` with no listeners registered.
2016-08-08 16:25:23.612113 PhoenixApp[525:64778] Sending `websocketFailed` with no listeners registered.
2016-08-08 16:25:23.742 [warn][tid:com.facebook.react.JavaScript] The regenerator/runtime module is deprecated; please import regenerator-runtime/runtime instead.
2016-08-08 16:25:23.741927 PhoenixApp[525:65027] The regenerator/runtime module is deprecated; please import regenerator-runtime/runtime instead.
2016-08-08 16:25:23.860 [info][tid:com.facebook.react.JavaScript] Running application "PhoenixApp" with appParams: {"rootTag":1,"initialProps":{}}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
2016-08-08 16:25:23.860251 PhoenixApp[525:65027] Running application "PhoenixApp" with appParams: {"rootTag":1,"initialProps":{}}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
2016-08-08 16:25:24.139 [info][tid:com.facebook.react.JavaScript] null
2016-08-08 16:25:24.138808 PhoenixApp[525:65027] null

接下来(每秒)

2016-08-08 16:31:43.159749 PhoenixApp[525:64956] [] __nw_connection_get_connected_socket_block_invoke 176 Connection has no connected handler
2016-08-08 16:31:45.372329 PhoenixApp[525:65445] [] __nw_connection_get_connected_socket_block_invoke 177 Connection has no connected handler
2016-08-08 16:31:47.575208 PhoenixApp[525:64955] [] __nw_connection_get_connected_socket_block_invoke 178 Connection has no connected handler
2016-08-08 16:31:49.788935 PhoenixApp[525:65445] [] __nw_connection_get_connected_socket_block_invoke 179 Connection has no connected handler
2016-08-08 16:31:51.970877 PhoenixApp[525:64955] [] __nw_connection_get_connected_socket_block_invoke 180 Connection has no connected handler
2016-08-08 16:31:54.173791 PhoenixApp[525:65445] [] __nw_connection_get_connected_socket_block_invoke 181 Connection has no connected handler

AppDelegate.m

/**
 * Copyright (c) 2015-present, Facebook, Inc.
 * All rights reserved.
 *
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 */

#import "AppDelegate.h"

#import "RCTBundleURLProvider.h"
#import "RCTRootView.h"

@implementation AppDelegate

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

  [[RCTBundleURLProvider sharedSettings] setDefaults];
  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];

  RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
                                                      moduleName:@"PhoenixTrello"
                                               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

设置:

react-native-cli:1.0.0 反应原生:0.32.0-rc.0 反应:15.3.0

Xcode 8 beta 4,iOS 10

4 个答案:

答案 0 :(得分:5)

在发布模式下尝试构建应用。

编辑方案

  • 选择“运行”标签
  • 选择信息标签
  • 将构建配置更改为发布
  • 构建并运行项目

当您的设备连接到Xcode时,Xcode会执行一些操作/优化并附加调试器。有时,此操作可防止显示错误。如果您在发布模式下运行应用程序,则会忽略此操作并且应用程序崩溃。

答案 1 :(得分:0)

您是否尝试构建jsBundle以使用App Offline。 ?

答案 2 :(得分:0)

我看到了这个错误,因为应用程序正在调用API来从远程服务器获取数据,而设备没有互联网连接。当设备连接到互联网时,错误就消失了。

答案 3 :(得分:0)

在ios文件夹中,查找并替换 Info.plist 文件中的代码:

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <false/>
        <key>NSExceptionDomains</key>
        <dict>
            <key>localhost</key>
            <dict>
                <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
        </dict>
    </dict>

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>

然后,运行:react-native run-ios