确定HKObject _validateForCreation上的崩溃

时间:2018-03-13 03:31:53

标签: ios swift apple-watch health-kit

在尝试将HKWorkout保存到HealthKit的设备(Apple Watch)上进行测试时,我正在为锻炼添加距离样本,卡路里,心率和vo2Max的样本。不幸的是,与this question不同的是,我没有像追溯那样详细...据我所知,它在添加样本时崩溃了但是我不知道它是哪个样本或为什么?

代码:

 private func addSamples(toWorkout workout: HKWorkout, from startDate: Date, to endDate: Date, handler: @escaping (Bool, Error?) -> Void) {


        let vo2MaxSample = HKQuantitySample(type: HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.vo2Max)!, quantity: vo2MaxQuantity(), start: startDate, end: endDate)

        var samples = [HKQuantitySample]()

        for distanceWalkingRunningSample in distanceWalkingRunningSamples {
            samples.append(distanceWalkingRunningSample)
        }

        for energySample in energySamples {
            samples.append(energySample)
        }

        samples.append(vo2MaxSample)
        samples.append(contentsOf: heartRateValues)

        // Add samples to workout
        healthStore.add(samples, to: workout) { (success: Bool, error: Error?) in

            if error != nil {
                print("Adding workout subsamples failed with error: \(String(describing: error))")
                handler(false, error)
            }

            if success {
                print("Success, samples have been added, workout Saved.")  //WorkoutStartDate = \(workout.startDate) WorkoutEndDate = \(workout.endDate)
                handler(true, nil)

            } else {
                print("Adding workout subsamples failed no error reported")
                handler(false, nil)
            }

        }
    }

追踪:

     Exception Type:  EXC_CRASH (SIGABRT)
            Exception Codes: 0x0000000000000000, 0x0000000000000000
            Exception Note:  EXC_CORPSE_NOTIFY
            Triggered by Thread:  0

            Application Specific Information:
            abort() called

            Filtered syslog:
            None found

            Last Exception Backtrace:
            0   CoreFoundation                  0x1bdf75e8 __exceptionPreprocess + 124
            1   libobjc.A.dylib                 0x1b15717c objc_exception_throw + 33
            2   CoreFoundation                  0x1bdf752c +[NSException raise:format:] + 103
            3   HealthKit                       0x273dbdde -[HKObject _validateForCreation] + 111
            4   HealthKit                       0x273dbc48 +[HKObject _newDataObjectWithMetadata:device:config:] + 219
            5   HealthKit                       0x273dbb30 +[HKSample _newSampleWithType:startDate:endDate:device:metadata:config:] + 159
            6   HealthKit                       0x273e9ba8 +[HKWorkout _workoutWithActivityType:startDate:endDate:workoutEvents:duration:totalActiveEnergyBurned:totalBasalEnergyBurned:totalDistance:totalSwimmingStrokeCount:totalFlightsClimbed:goalType:goal:device:metadata:config:] + 431
            7   HealthKit                       0x274a9342 +[HKWorkout workoutWithActivityType:startDate:endDate:workoutEvents:totalEnergyBurned:totalDistance:device:metadata:] + 109
            8   HealthKit                       0x274a9160 +[HKWorkout workoutWithActivityType:startDate:endDate:workoutEvents:totalEnergyBurned:totalDistance:metadata:] + 87
    9   Watch Extension                 0x002b7ecc 0x290000 + 163532
    10  Watch Extension                 0x002b79fc 0x290000 + 162300
    11  Watch Extension                 0x002bb7ac 0x290000 + 178092
    12  Watch Extension                 0x002ab9e8 0x290000 + 113128
    13  Watch Extension                 0x002a9660 0x290000 + 104032
    14  Watch Extension                 0x002a8f68 0x290000 + 102248
    15  Watch Extension                 0x002a7748 0x290000 + 96072
    16  libdispatch.dylib               0x1b8875ec _dispatch_call_block_and_release + 5
    17  libdispatch.dylib               0x1b8875c8 _dispatch_client_callout + 1
    18  libdispatch.dylib               0x1b897822 _dispatch_main_queue_callback_4CF$VARIANT$mp + 853
    19  CoreFoundation                  0x1bdb31ac __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 5
    20  CoreFoundation                  0x1bdb0f42 __CFRunLoopRun + 929
    21  CoreFoundation                  0x1bcfe96a CFRunLoopRunSpecific + 349
    22  GraphicsServices                0x1d8beb92 GSEventRunModal + 89
    23  UIKit                           0x21f556da UIApplicationMain + 151
    24  libxpc.dylib                    0x1bb2fd78 _xpc_objc_main + 581
    25  libxpc.dylib                    0x1bb31720 xpc_main + 149
    26  Foundation                      0x1c7bbf24 -[NSXPCListener resume] + 175
    27  PlugInKit                       0x22ccbf40 -[PKService run] + 709
    28  WatchKit                        0x2b5777b8 main + 157
    29  libdyld.dylib                   0x1b8e2b8e 0x1b8df000 + 15246

    Thread 0 name:  Dispatch queue: com.apple.main-thread
    Thread 0 Crashed:
    0   libsystem_kernel.dylib          0x1b9e443c __pthread_kill + 8
    1   libsystem_pthread.dylib         0x1baec270 pthread_kill$VARIANT$mp + 334
    2   libsystem_c.dylib               0x1b96d28e abort + 106
    3   libc++abi.dylib                 0x1b136cfe __cxa_bad_cast + 0
    4   libc++abi.dylib                 0x1b136e8a default_unexpected_handler+ 16010 () + 0
    5   libobjc.A.dylib                 0x1b1573e0 _objc_terminate+ 29664 () + 102
    6   libc++abi.dylib                 0x1b1493fc std::__terminate(void (*)+ 91132 ()) + 6
    7   libc++abi.dylib                 0x1b148ed6 __cxxabiv1::exception_cleanup_func+ 89814 (_Unwind_Reason_Code, _Unwind_Exception*) + 0
    8   libobjc.A.dylib                 0x1b157274 _objc_exception_destructor+ 29300 (void*) + 0
    9   CoreFoundation                  0x1bdf7530 -[NSException initWithCoder:] + 0
    10  HealthKit                       0x273dbde2 -[HKObject _validateForCreation] + 116
    11  HealthKit                       0x273dbc4c +[HKObject _newDataObjectWithMetadata:device:config:] + 224
    12  HealthKit                       0x273dbb34 +[HKSample _newSampleWithType:startDate:endDate:device:metadata:config:] + 164
    13  HealthKit                       0x273e9bac +[HKWorkout _workoutWithActivityType:startDate:endDate:workoutEvents:duration:totalActiveEnergyBurned:totalBasalEnergyBurned:totalDistance:totalSwimmingStrokeCount:totalFlightsClimbed:goalType:goal:device:metadata:config:] + 436
    14  HealthKit                       0x274a9346 +[HKWorkout workoutWithActivityType:startDate:endDate:workoutEvents:totalEnergyBurned:totalDistance:device:metadata:] + 114
    15  HealthKit                       0x274a9164 +[HKWorkout workoutWithActivityType:startDate:endDate:workoutEvents:totalEnergyBurned:totalDistance:metadata:] + 92
16  Watch Extension                 0x002b7ed0 0x290000 + 163536
17  Watch Extension                 0x002b7a00 0x290000 + 162304
18  Watch Extension                 0x002bb7b0 0x290000 + 178096
19  Watch Extension                 0x002ab9ec 0x290000 + 113132
20  Watch Extension                 0x002a9664 0x290000 + 104036
21  Watch Extension                 0x002a8f6c 0x290000 + 102252
22  Watch Extension                 0x002a774c 0x290000 + 96076
23  libdispatch.dylib               0x1b8875f0 _dispatch_call_block_and_release + 10
24  libdispatch.dylib               0x1b8875cc _dispatch_client_callout + 6
25  libdispatch.dylib               0x1b897826 _dispatch_main_queue_callback_4CF$VARIANT$mp + 858
26  CoreFoundation                  0x1bdb31b0 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 10
27  CoreFoundation                  0x1bdb0f46 __CFRunLoopRun + 934
28  CoreFoundation                  0x1bcfe96e CFRunLoopRunSpecific + 354
29  GraphicsServices                0x1d8beb96 GSEventRunModal + 94
30  UIKit                           0x21f556de UIApplicationMain + 156
31  libxpc.dylib                    0x1bb2fd7c _xpc_objc_main + 586
32  libxpc.dylib                    0x1bb31724 xpc_main + 154
33  Foundation                      0x1c7bbf28 service_connection_handler + 0
34  PlugInKit                       0x22ccbf44 -[PKService run] + 714
35  WatchKit                        0x2b5777bc main + 162
36  libdyld.dylib                   0x1b8e2b92 start + 2

0 个答案:

没有答案