iOS真机上运行特别慢,导致奔溃闪退,分析日志中...



  • React Native开发的App,在iOS上运行后,程序长时间停留在白屏页面,基本处于卡死状态。

    抓取的iOS奔溃日志为:
    Exception Type: EXC_CRASH (SIGKILL)
    Exception Codes: 0x0000000000000000, 0x0000000000000000
    Exception Note: EXC_CORPSE_NOTIFY
    Termination Reason: Namespace SPRINGBOARD, Code 0x8badf00d
    Triggered by Thread: 0

    Filtered syslog:
    None found

    Thread 0 name: Dispatch queue: com.apple.main-thread
    Thread 0 Crashed:
    0 libsystem_kernel.dylib 0x0000000188e8f260 semaphore_wait_trap + 8
    1 libdispatch.dylib 0x0000000188d7d5e8 _os_semaphore_wait + 24
    2 libdispatch.dylib 0x0000000188d7cca0 _dispatch_semaphore_wait_slow + 140
    3 CFNetwork 0x000000018a56fcec CFURLConnectionSendSynchronousRequest + 284
    4 CFNetwork 0x000000018a59c2a4 +[NSURLConnection sendSynchronousRequest:returningResponse:error:] + 120
    5 LeyaoMusic 0x00000001001a1c64 -[RCTBundleURLProvider isPackagerRunning:] (RCTBundleURLProvider.m:76)
    6 LeyaoMusic 0x00000001001a1f14 -[RCTBundleURLProvider guessPackagerHost] (RCTBundleURLProvider.m:92)
    7 LeyaoMusic 0x00000001001a2124 -[RCTBundleURLProvider packagerServerHost] (RCTBundleURLProvider.m:106)
    8 LeyaoMusic 0x00000001001a22e8 -[RCTBundleURLProvider jsBundleURLForBundleRoot:fallbackResource:] (RCTBundleURLProvider.m:123)
    9 LeyaoMusic 0x00000001000e05ec -[AppDelegate application:didFinishLaunchingWithOptions:] (AppDelegate.m:22)

    进一步定位,发现:
    #if RCT_DEV

    • (BOOL)isPackagerRunning:(NSString *)host
      {
      NSURL *url = [serverRootWithHost(host) URLByAppendingPathComponent:@"status"];
      NSURLRequest *request = [NSURLRequest requestWithURL:url];
      NSURLResponse *response;
      NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:NULL];
      NSString *status = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
      return [status isEqualToString:@"packager-status:running"];
      }

    问题出在 NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:NULL];这句话上,发送同步请求,在主线程执行,由于长时间没有得到响应,导致触发系统的看门狗,而被系统强制关闭。

    我在模拟器上运行都是正常的,在真机上才会出现闪退的问题,但是这好像也是react native帮我们生成好的加载框架,不知道应该怎么修改或者优化~~~各位道友有遇到过类似的问题吗?


  • administrators

    是不是有什么防火墙服务



  • 问题找到了,是真机测试的时候,需要将bundle打包导入。


登录后回复