iOS 应用程序崩溃,调试时 xcode 显示“与 X 的 iPhone 的连接丢失”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26020832/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 02:46:21  来源:igfitidea点击:

iOS app crashes, xcode says 'Lost connection to X's iPhone' when debugging

iosiphonexcodecrash

提问by SolidSun

My app crashes and I need some advice to find and fix the problem. It is not a device or cable problem because it happens with all devices and not only when debugging. Xcode won't stop on an exception breakpoint the app just simply stops running with no error information. When debugging xcode only says 'Lost connection to X's iPhone'. I have the following log from the device, see MY_CRASHING_APP:

我的应用程序崩溃了,我需要一些建议来查找和解决问题。这不是设备或电缆问题,因为它发生在所有设备上,而不仅仅是在调试时。Xcode 不会在异常断点处停止,应用程序只是简单地停止运行而没有错误信息。调试 xcode 时只显示“与 X 的 iPhone 的连接丢失”。我从设备有以下日志,请参阅 MY_CRASHING_APP:

Incident Identifier: 85730E97-BA21-4C72-8AD1-02075A8FD9A7
CrashReporter Key:   d9e9eb14ac1801fea11e662a394244d7caf29154
Hardware Model:      iPhone4,1
OS Version:          iPhone OS 8.0 (12A365)
Kernel Version:      Darwin Kernel Version 14.0.0: Tue Aug 19 15:08:02 PDT 2014; root:xnu-2783.1.72~8/RELEASE_ARM_S5L8940X
Date:                2014-09-24 15:02:41 +0200
Time since snapshot: 325 ms

Free pages:                              20793
Active pages:                            20412
Inactive pages:                          10678
Speculative pages:                       1757
Throttled pages:                         55906
Purgeable pages:                         699
Wired pages:                             21196
File-backed pages:                       30263
Anonymous pages:                         2584
Compressions:                            76385
Decompressions:                          3948
Compressor Size:                         81
Uncompressed Pages in Compressor:        61
Page Size:                               4096
Largest process:   MY_CRASHING_APP

Processes
     Name       |            <UUID>                |     CPU Time|     rpages|       purgeable| recent_max| lifetime_max| fds |  [reason]         | (state)

       coreduetd <675ac3d39b193f9bba42896818431859>         0.049         124                0           -           391   50     [vnode-limit]     (daemon) (idle)
           homed <77bcbc47e2723e269b0ff9d115658259>         0.052         146                0           -           458   50     [vnode-limit]     (daemon) (idle)
           gamed <a51b1ad16b693a75aeaaf2166e7b1b0b>         0.049          38                0           -            74   50     [vnode-limit]     (daemon) (idle)
             lsd <72b4494834d3357bb8aa32fd5b5c8e83>         0.068         161                0           -           368   50     [vnode-limit]     (daemon)
   InCallService <88e149874b1c35f2b8adbeee958d7258>        18.461        1289                0           -          3238   50     [vnode-limit]     (resume) (continuous)
 MY_CRASHING_APP <1542054cd5393df29827ca1a6bd34e04>        59.116       24504              600           -         29490 1600     [vnode-limit]     (frontmost) (resume)
            ptpd <c0bc1e573edb3bcebea0f3140a139421>         3.442         878                0           -          1634   50                       (daemon)
        BTServer <1b7372b3ae393847b1c3ccaa720e991e>         3.057         393                0           -          1437   50                       (daemon)
       lockdownd <bb602fb4b5ac3b51af2d22c4fdce9778>        11.306         271                0           -           761   50                       (daemon)
         imagent <01ebc2c08d7f36059714967efaa86e78>        19.892         585                0           -          1286   50                       (daemon)
       locationd <9727e24fbe4f357cb27d7bc8cf882c93>       489.694        1665                0           -          3586   50                       (daemon)
identityservices <13c2b979d6433252a011087be05e1aa5>        22.999         696                0          +2          1585   50                       (daemon)
      discoveryd <dff5d0d2edf43b45b0c7fbd4a3e1b677>        93.758         589                0           -          1077  100                       (daemon)
           wifid <5fb79228aa653a9bb725217b9cb891e6>        63.420         571                0           -          1098   50                       (daemon)
   iaptransportd <ae70565455de38f3aab8993e9d109207>         7.713         306                0           -           579   50                       (daemon)
    mediaserverd <b5ba58774a853d43a17559ae76a6f918>       649.476        1025               64           -          6134   50                       (daemon)
         syslogd <a5a138dc01cd34d19bbe336c03099ce7>        40.100         201                0           -           384   50                       (daemon)
          powerd <b3163caaebd53f7aa42634836472ea04>        43.199         231                0           -           474   50                       (daemon)
            apsd <17af2320ccfb3e668b6455b95b4612ce>        37.461         631                0           -          1445   50                       (daemon)
        networkd <a657abe0ce803333b886876a8f7a36e0>        77.271         596                0           -          1297   50                       (daemon)
     dataaccessd <db655c44d5c830dc9e5f34f7edcb17a4>       243.259        1777                0           -          3097  100                       (daemon)
             vmd <88cebb23d0f1344db23e1896b1787f2d>         0.505         204                0           -           617   50                       (daemon)
            iapd <e84bb9b7cf7530babc36c6ca37b7f345>        11.963         453                0           -          1673   50                       (daemon)
    syslog_relay <9e18dbcbcc07374e9d14c732b8dabad2>         1.424          98                0           -           189   50                       (daemon)
          voiced <2d24fa3e32533f2f8298743eaf348d63>         0.179         210                0           -           581   50                       (daemon)
    itunesstored <d50d5b1c3f693694a2eee878aae8facf>         0.573         908                0           -          1759   50                       (daemon)
     SpringBoard <3e0aacaca7103aa09a71e5c9fee3e012>       841.081        7088               29           -         16912   50                      
      backboardd <117d65aca8ce3ba68c7fd87d9ab81da6>      3424.058        6678              625           -          4409   50                       (daemon)
  UserEventAgent <2f6c74a697943aed899faebac621e4c3>       316.816         848                0           -          2101  200                       (daemon)
         configd <64e4db8bced23463b446c4b7c868fcfa>        31.906         416                0           -           933   50                       (daemon)
       fseventsd <a393d343a7533860b5c1eddb922a33f1>        20.088         405                0           -           805   50                       (daemon)
    fairplayd.H1 <c3856f0573fb3f9887721a239507f28b>        30.647         159                0           -          1096   50                       (daemon)
      assertiond <032107d4db2b36ddac986060d8c62f73>        26.282         289                0           -           702   50                       (daemon)
   wirelessproxd <ba82fe3b38f63f2b8b8807a2bf97aadd>         1.071         179                0           -           643   50                       (daemon)
       distnoted <e8f9e76e751838a880dad2d4a953f814>         4.457         193                0           -           254   50                       (daemon)
discoveryd_helpe <84abc0c6dd5b37a8b2c8323881e16da7>         0.493         123                0           -           466   50                       (daemon)
             ubd <5f4f0054821e3b41b543a4d9f4176291>         9.040         730                0           -          1540   50                       (daemon)
filecoordination <68a3848887853629adae42f5828a5443>         2.731         251                0           -           649  100                       (daemon)
      aggregated <ab0d307a392f36cc827709d24c4b8696>      1335.558        1081                0           -          1688   50                       (daemon)
      DTMobileIS <086152f142ac30a686a172b148d38fbc>       109.156         474                0           -          1724   50                       (daemon)
     touchsetupd <d8aabe65f2d23f6ab7704bbccc6c2ba1>         0.388         158                0           -           464   50                       (daemon)
        cfprefsd <6e5dcfe209183c719091d07edad590da>         0.150         166                0           -           320   50                       (daemon)
       accountsd <9eb0309b021033c6b24ce65da48fa228>         0.665         595                0           -          1909   50                       (daemon)
      CommCenter <0e1ced0eddce346ba27e9f54886ef025>       669.306        1543                0           -          4623   50                       (daemon)
         notifyd <7beaf472572334d4989a40473776f635>        61.698         272                0           -           309   50                       (daemon)
     ReportCrash <b36d5780860a3dfcbb146b2cc6bca339>         0.062         146                0           -           443   50                       (daemon)

**End**

UPDATE:

更新:

It turned out to be a memory issue. The app was allocating a lot of memory very quickly and the OS terminated the app. It was strange that Xcode did not log a memory warning while in Instruments show that the app received a LOT of warnings. Other apps that used the same amount of memory got away with no memory warnings. My guess is that those were not allocating memory at such a fast rate.

结果证明是内存问题。该应用程序很快分配了大量内存,操作系统终止了该应用程序。奇怪的是,Xcode 没有记录内存警告,而在 Instruments 中显示该应用程序收到了很多警告。其他使用相同内存量的应用程序没有出现内存警告。我的猜测是那些没有以如此快的速度分配内存。

The app was running on an iPhone 4S and it got killed at around 90MB memory usage.

该应用程序在 iPhone 4S 上运行,它在大约 90MB 的内存使用量时被杀死。

What confused me is other out of memory issues all had Purgeable pages: 0. So I'm guessing this is not exactly an out of memory but too much memory usage in a short time?

让我困惑的是其他所有的内存不足问题Purgeable pages: 0。所以我猜这不是内存不足,而是短时间内内存使用过多?

回答by Chris

Just chipping in for anyone else who is struggling on this one.

只是为其他正在为此而苦苦挣扎的人提供帮助。

For me the solution was to restart my device.

对我来说,解决方案是重新启动我的设备。

回答by respectTheCode

I had this same issue when loading a bunch of very large images (5000px x 5000px) in UIImages. Luckily the images were not supposed to be anywhere near that big and I just needed to resize them.

UIImages 中加载一堆非常大的图像(5000px x 5000px)时,我遇到了同样的问题。幸运的是,图像不应该接近那么大,我只需要调整它们的大小。

回答by Beninho85

This bug appears frequently since I switched on iOS 11 Beta. Sometimes restarting the device works, sometimes my computer...

自从我打开 iOS 11 Beta 以来,这个错误经常出现。有时重新启动设备有效,有时我的电脑...

回答by Andy Darwin

Yes, it is a memory issue, or you have opened too many threads. I have met this problem before. The problem I met like this:

是的,这是内存问题,或者您打开了太多线程。我以前遇到过这个问题。我遇到的问题是这样的:

When I delete a photo, which may cost about 0.2s, I would like to show a toast(MBProgressHUD) to user, and GCD to hide the toast after deleting.
When I tried to delete 100 photos, it is okay. However, when I tried to delete 200 photos, the app might be crashed. When I tried to delete 300 photos, the iPhone always restart itself.

当我删除一张照片时,可能需要大约 0.2 秒,我想MBProgressHUD向用户显示一个 toast( ),并在删除后 GCD 隐藏 toast。
当我尝试删除 100 张照片时,没问题。但是,当我尝试删除 200 张照片时,该应用程序可能会崩溃。当我尝试删除 300 张照片时,iPhone 总是自动重启。

回答by Jasper

As Andy Darwin suggested, it is a memory issue.

正如安迪达尔文所建议的那样,这是一个内存问题。

I had this problem on older devices when adding an UIImageViewwith animationImages.

添加UIImageViewwith时,我在旧设备上遇到了这个问题animationImages

回答by Tim

Posting for posterity, as I recently experienced this 'crash' and it wasn't due to memory issues as others have suggested:

为后人发帖,因为我最近经历了这种“崩溃”,这不是因为其他人建议的内存问题:

In rare cases, this can be an issue with the cord used to connect the iPhone to the computer. I had a faulty lightning cable, that would sporadically lose connection to my mac. The solution was to by a new one!

在极少数情况下,这可能是用于将 iPhone 连接到计算机的电源线的问题。我的避雷线有问题,偶尔会失去与我的 mac 的连接。解决方案是通过一个新的!

回答by Apneist

Just to add that I had the same issue running my app both on and old Ipad 3 and Iphone 6. What ended up being the problem was I had accidentally saved 2 images of the project as a 40mb and a 20mb version. So it was a memory issue. I downsized them as 1mb each, and issue solved.

补充一点,我在旧的 Ipad 3 和 Iphone 6 上运行我的应用程序时遇到了同样的问题。最终的问题是我不小心将项目的 2 个图像保存为 40mb 和 20mb 版本。所以这是一个内存问题。我将它们每个缩小为 1mb,问题解决了。

回答by FisherMartyn

In my case, I use UICollectionView to show a bunch of photos and when I want to perform reloadDatato the view, crash occurs, while the memory usage is not that high (less than 100M). Besides memory issue, I think reloadDataof UICollectionView or UITableView may cause this, too.

就我而言,我使用 UICollectionView 来显示一堆照片,当我想执行reloadData视图时,会发生崩溃,而内存使用率并不高(小于 100M)。除了内存问题,我认为reloadDataUICollectionView 或 UITableView 也可能导致这种情况。