为什么我的应用程序在模拟器中运行但在尝试在我的iPhone上启动时崩溃?

时间:2017-05-03 03:52:57

标签: swift core-data ios-simulator

我正在使用Xcode 8.3.2在Swift 3中编写应用程序。我的应用程序在模拟器中运行良好,但当我尝试在我的iPhone(iOS 10.3.1)上运行它时,我收到一条丑陋的错误消息:

   libswiftCore.dylib`function signature specialization <preserving fragile attribute, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, file : Swift.StaticString, line : Swift.UInt, flags : Swift.UInt32) -> Swift.Never:
    0x1005203d0 <+0>:   stp    x26, x25, [sp, #-0x50]!
    0x1005203d4 <+4>:   stp    x24, x23, [sp, #0x10]
    0x1005203d8 <+8>:   stp    x22, x21, [sp, #0x20]
    0x1005203dc <+12>:  stp    x20, x19, [sp, #0x30]
    0x1005203e0 <+16>:  stp    x29, x30, [sp, #0x40]
    0x1005203e4 <+20>:  add    x29, sp, #0x40            ; =0x40 
    0x1005203e8 <+24>:  mov    x19, x6
    0x1005203ec <+28>:  mov    x20, x5
    0x1005203f0 <+32>:  mov    x21, x4
    0x1005203f4 <+36>:  mov    x22, x3
    0x1005203f8 <+40>:  mov    x23, x2
    0x1005203fc <+44>:  mov    x24, x1
    0x100520400 <+48>:  mov    x25, x0
    0x100520404 <+52>:  adr    x8, #0xf11fc              ; protocol descriptor for Swift._DefaultCustomPlaygroundQuickLookable + 136
    0x100520408 <+56>:  nop    
    0x10052040c <+60>:  add    x0, x8, #0x10             ; =0x10 
    0x100520410 <+64>:  mov    w1, #0x28
    0x100520414 <+68>:  orr    w2, wzr, #0x7
    0x100520418 <+72>:  bl     0x100520750               ; swift_rt_swift_allocObject
    0x10052041c <+76>:  mov    x8, x0
    0x100520420 <+80>:  stp    x22, x21, [x8, #0x10]
    0x100520424 <+84>:  strb   w20, [x8, #0x20]
    0x100520428 <+88>:  str    w19, [x8, #0x24]
    0x10052042c <+92>:  adr    x3, #0x40440              ; partial apply forwarder for Swift.(_fatalErrorMessage (Swift.StaticString, Swift.StaticString, file : Swift.StaticString, line : Swift.UInt, flags : Swift.UInt32) -> Swift.Never).(closure #2)
    0x100520430 <+96>:  nop    
    0x100520434 <+100>: mov    x0, x25
    0x100520438 <+104>: mov    x1, x24
    0x10052043c <+108>: mov    x2, x23
    0x100520440 <+112>: mov    x4, x8
    0x100520444 <+116>: bl     0x1004014dc               ; function signature specialization <preserving fragile attribute, Arg[1] = [Closure Propagated : reabstraction thunk helper from @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> () to @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> (@out ()), Argument Types : [@callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) -> ()]> of generic specialization <preserving fragile attribute, ()> of Swift.StaticString.withUTF8Buffer <A> ((Swift.UnsafeBufferPointer<Swift.UInt8>) -> A) -> A
->  0x100520448 <+120>: brk    #0x1

我设置了一个异常断点,让我得到了这段代码:

    if let defaultFormula = dataManager.fetchDefaultFormula(moc) {
        self.formula = defaultFormula.first! <<< Unexpectedly found nil...
    }

这是它正在调用的函数:

  func fetchDefaultFormula(_ moc: NSManagedObjectContext) -> [Formula]? {
        let defaultFormulaID = UserDefaults.formula()
        let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Formula")
        let filterPredicate = NSPredicate(format: "uuid = [c] %@", defaultFormulaID)
        fetchRequest.predicate = filterPredicate

        do {
            return try moc.fetch(fetchRequest) as? [Formula]
        } catch {
            fatalError("There was an error fetching the lifts")
        }
        return nil
    }

获取请求返回0值,因此我很清楚为什么当我强行打开它时我得到异常。但是,对象属性“formula”必须具有值。该应用程序所做的第一件事是检查持久性存储中是否存在默认数据(如可用的公式),如果不存在,则添加它。我重置了模拟器,它尽职尽责地添加了它们,但似乎这不会发生在iPhone上。如果我有办法确定在iPhone上运行时是否将记录添加到商店,请赐教。

我发现了一些SO线程,其他人遇到了这个神秘的错误(大而丑陋的错误,而不是意料之外的错误)并且我已经尝试了所有建议的补救措施:

  • 清理了拔掉iPhone的项目,将其重新插入
  • 重启所有设备
  • 将团队更改为无并回复给我
  • 已关闭自动管理签名并将其重新打开
  • 下载了我当前的证书
  • 在Build Settings
  • 中将一些标志从No转为Yes

我不知道从哪里开始已经用尽了我能找到的所有建议。

非常感谢任何建议。

1 个答案:

答案 0 :(得分:2)

嗯,我想有一件事我没试过 - 首先从我的手机上卸载应用程序,然后在手机上构建并运行它。

所以我真的不知道根本原因是什么,但至少这解决了这个问题。