启动时崩溃 - ios 8.1 因为添加了 UIButton 的子视图。 EXC_BREAKPOINT(信号陷阱)

Crash at launch - ios 8.1 because adding UIButton's subview. EXC_BREAKPOINT (SIGTRAP)

我刚刚被 Apple 拒绝了,原因如下:

We were unable to review your app, as it crashed on launch on the following device(s): - iPhone 5S running iOS 8.1- iPhone 6 running iOS 8.1- iPhone 6 Plus running iOS 8.1

这是我所做的:

我确实用模拟器 ios 8.1,8.2 中的设备对其进行了测试。我还使用读取设备对其进行了测试:iphone 4 运行ning ios 7.1,ipad 运行ning ios 8.3。根本没有崩溃。

根据他们发送的崩溃日志,我使用 Symbolicator 生成以下符号化日志:

Process:             Meety [1125]
Path:                /private/var/mobile/Containers/Bundle/Application/12CA9A59-184C-4B7E-9D2A-0B4703363AA2/Meety.app/Meety
Identifier:          com.cungcode.Meety
Version:             1 (1.0)
Code Type:           ARM-64 (Native)
Parent Process:      launchd.development [1]

Date/Time:           2015-05-16 05:34:46.952 -0700
Launch Time:         2015-05-16 05:34:46.165 -0700
OS Version:          iOS 8.1 (12B411)
UDID:                d1c1574d0e021ab0d30ce26e69978227c7080d3c
Report Version:      105

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x000000010016bdf8
Triggered by Thread:  0

Filtered syslog:
2015-05-16 05:34:46.535 Meety[1125]: <Error> assertion failed: 12B411: libxpc.dylib + 71820 [AD580443-238D-3997-8D09-004C210D0C18]: 0x7d

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
__TFC5Meety20MainTabBarController24addCenterButtonWithImagefS0_FTCSo7UIImage14highlightImageGSqS1___T_ MainTabBarController.swift:227
__TFC5Meety20MainTabBarController11viewDidLoadfS0_FT_T_ MainTabBarController.swift:57
2   UIKit                           0x000000018a72ce80 0x18a71c000 + 69248
3   UIKit                           0x000000018a72cb90 0x18a71c000 + 68496
4   UIKit                           0x000000018a733258 0x18a71c000 + 94808
5   UIKit                           0x000000018a7309d8 0x18a71c000 + 84440
6   UIKit                           0x000000018a7a1a00 0x18a71c000 + 547328
7   UIKit                           0x000000018a9b5434 0x18a71c000 + 2724916
8   UIKit                           0x000000018a9b79ac 0x18a71c000 + 2734508
9   UIKit                           0x000000018a9b6044 0x18a71c000 + 2728004
10  FrontBoardServices              0x000000018e2c163c 0x18e2a8000 + 103996
11  CoreFoundation                  0x0000000185f36120 0x185e58000 + 909600
12  CoreFoundation                  0x0000000185f35228 0x185e58000 + 905768
13  CoreFoundation                  0x0000000185f3384c 0x185e58000 + 899148
14  CoreFoundation                  0x0000000185e611f0 0x185e58000 + 37360
15  UIKit                           0x000000018a797788 0x18a71c000 + 505736
16  UIKit                           0x000000018a792780 0x18a71c000 + 485248
_main AppDelegate.swift:16
18  libdyld.dylib                   0x0000000196dc6a04 0x196dc4000 + 10756

Thread 1 name:  Dispatch queue: com.apple.libdispatch-manager
Thread 1:
0   libsystem_kernel.dylib          0x0000000196ec4c94 0x196ec4000 + 3220
1   libdispatch.dylib               0x0000000196dac97c 0x196d9c000 + 67964
2   libdispatch.dylib               0x0000000196d9f3b0 0x196d9c000 + 13232

Thread 2:
0   libsystem_kernel.dylib          0x0000000196edfc78 0x196ec4000 + 113784
1   libsystem_pthread.dylib         0x0000000196f79390 0x196f78000 + 5008
2   libsystem_pthread.dylib         0x0000000196f78fa4 0x196f78000 + 4004

Thread 3:
0   libsystem_kernel.dylib          0x0000000196edfc78 0x196ec4000 + 113784
1   libsystem_pthread.dylib         0x0000000196f79390 0x196f78000 + 5008
2   libsystem_pthread.dylib         0x0000000196f78fa4 0x196f78000 + 4004

Thread 4:
0   libsystem_kernel.dylib          0x0000000196edfc78 0x196ec4000 + 113784
1   libsystem_pthread.dylib         0x0000000196f79390 0x196f78000 + 5008
2   libsystem_pthread.dylib         0x0000000196f78fa4 0x196f78000 + 4004

Thread 5:
0   libsystem_kernel.dylib          0x0000000196edfc78 0x196ec4000 + 113784
1   libsystem_pthread.dylib         0x0000000196f79390 0x196f78000 + 5008
2   libsystem_pthread.dylib         0x0000000196f78fa4 0x196f78000 + 4004

Thread 6:
0   libsystem_kernel.dylib          0x0000000196edfc78 0x196ec4000 + 113784
1   libsystem_pthread.dylib         0x0000000196f79390 0x196f78000 + 5008
2   libsystem_pthread.dylib         0x0000000196f78fa4 0x196f78000 + 4004

Thread 7:
0   libsystem_kernel.dylib          0x0000000196edfc78 0x196ec4000 + 113784
1   libsystem_pthread.dylib         0x0000000196f79390 0x196f78000 + 5008
2   libsystem_pthread.dylib         0x0000000196f78fa4 0x196f78000 + 4004

Thread 8:
0   libsystem_kernel.dylib          0x0000000196edfc78 0x196ec4000 + 113784
1   libsystem_pthread.dylib         0x0000000196f79390 0x196f78000 + 5008
2   libsystem_pthread.dylib         0x0000000196f78fa4 0x196f78000 + 4004

Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000000   x1: 0x0000000196f71958   x2: 0x000000015fd233e0   x3: 0x000000000000001e
    x4: 0x0000000000000010   x5: 0x0000000000000001   x6: 0x0000000000000000   x7: 0x0000000000000000
    x8: 0x0000000000000000   x9: 0x000000015fe0c850  x10: 0x0000000000000000  x11: 0x000000000000005e
   x12: 0x0000000000000001  x13: 0x000000000017a17c  x14: 0x0000000000000015  x15: 0x0000000000000000
   x16: 0x0000000100a8217c  x17: 0x0000000000000000  x18: 0x0000000000000000  x19: 0x00000001740995a0
   x20: 0x00000001700997d0  x21: 0x000000015fe0c850  x22: 0x0000000000000000  x23: 0x000000015fd233e0
   x24: 0x0000000100ab30c8  x25: 0x0000000100856dd0  x26: 0x0000000100856dd0  x27: 0x000000019aa4a0a8
   x28: 0x0000000000000001  fp: 0x000000016fd1e160   lr: 0x000000010016b8c0
    sp: 0x000000016fd1e100   pc: 0x000000010016bdf8 cpsr: 0x80000000

所以在我看来,错误必须在以下代码中:

(在 MainTabBarController 中)

@IBOutlet weak var mapButton: UIButton!

override func viewDidLoad()
{

    super.viewDidLoad()
    self.delegate = self
    var middleImage:UIImage = UIImage(named:"MapButton")!
    var highlightedMiddleImage:UIImage = UIImage(named:"MapButtonHighlighted")!
    addCenterButtonWithImage(middleImage, highlightImage: highlightedMiddleImage) //Line 57 --> Correct!!
    self.tabBar.barTintColor = UIColor.blackColor()

}

func addCenterButtonWithImage(buttonImage: UIImage, highlightImage:UIImage?)
{
    mapButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton //UPDATE 1: LINE 206 --> CRASH HERE 
    mapButton.autoresizingMask = UIViewAutoresizing.FlexibleBottomMargin|UIViewAutoresizing.FlexibleLeftMargin|UIViewAutoresizing.FlexibleRightMargin|UIViewAutoresizing.FlexibleTopMargin

    mapButton.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);
    mapButton.setBackgroundImage(buttonImage, forState: UIControlState.Normal)
    mapButton.setBackgroundImage(highlightImage, forState: UIControlState.Highlighted)
    //Center the button on tabbar        
    var heightDifference:CGFloat = buttonImage.size.height - self.tabBar.frame.size.height;

    if heightDifference < 0 {
        mapButton.center = self.tabBar.center;
    }
    else
    {
        var center:CGPoint = self.tabBar.center;
        center.y = center.y - heightDifference/2.0;
        mapButton.center = center;
    }

    mapButton.addTarget(self, action: "changeSelectedTabToMapTabController:", forControlEvents: UIControlEvents.TouchUpInside)

    self.view.addSubview(mapButton)
} //LINE 227: PROBABLY CRASH HERE, BUT I THINK IT CRASH ON LINE 206

上面代码的意思是,我想创建一个类似Instagram的标签栏。所以我在 5 项选项卡栏中的 3 选项卡前面添加了一个按钮。在模拟器 ios 8.1 中如下所示:

1) 代码很简单,我无法找出它在 ios 8.1 中崩溃的原因。现在我没有真正的设备 运行ning ios 8.1 来测试它所以我问你是否可以在代码中找到异常的东西。

2) 是否有可能是因为配置文件有问题导致应用程序崩溃?但我认为这不是我的情况,因为我使用分发配置文件存档,并通过 iTunes 和 TestFlight 安装 ipa 到我的 ipad 它可以 运行 ok.

抱歉,问题很长。任何帮助将不胜感激!

更新 1: 我通过命令行符号再次确认崩溃,如here中西藏海岸的回答所述。然后我得到了崩溃必须在代码的第206行:

mapButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton

这种启蒙肯定有问题。我没有为这个按钮使用情节提要,但我以编程方式创建。我的朋友使用 XCode 6.3(我用的是 6.2),打开我的项目时看到很多与 "as"、“!”相关的编译错误。和 ”?”。我想我要把我的 XCode 更新到 6.3,看看我是否有编译错误 "as" 在第 206 行。

通过将编辑方案中的构建配置设置为 Release for 运行,只需检查 运行 应用程序选项卡并查看崩溃是否仍然发生,它将帮助您进行调试,因为构建在发布模式下崩溃。我觉得它主要是 swift 编译器问题,如果是这样,您可以通过将 swift 编译器优化从最快更改为 none 来避免它。我不确定这是否是一个理想的解决方案,但看看是否有帮助。 :]

终于拿到真机进行测试了。它在以下行崩溃:

mapButton.autoresizingMask = UIViewAutoresizing.FlexibleBottomMargin|UIViewAutoresizing.FlexibleLeftMargin|UIViewAutoresizing.FlexibleRightMargin|UIViewAutoresizing.FlexibleTopMargin

原因:mapButton 为零。很奇怪,因为这条线就在上面:

mapButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton

所以面对这个初始化程序不要初始化我的按钮。所以我可能同意 Chandan005 关于编译器问题的观点。我将代码更改为:

   let frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height)
    button = UIButton(frame: frame)

现在适用于 iPhone 6,ios 8.1。我再次提交了我的应用程序,希望这次能通过。我在我的博客中写到了这个错误 here