gpt4 book ai didi

ios - HomeKit 崩溃原因 : '-[__NSDate length]: but Bool sent

转载 作者:行者123 更新时间:2023-11-28 06:25:18 25 4
gpt4 key购买 nike

tl;dr - 问题中的代码是正确的。在另一方崩溃的原因。

挑战在于控制支持 Elgato Eve Energy HomeKit 的 socket 。直到代码开始,一切正常,所以选择了正确的房间、配件等。代码确实关闭了 socket ,但紧接着应用程序崩溃了。

guard let services = accessory?.services else {
print("No Service")
return
}
for service in services {
if service.serviceType == HMServiceTypeOutlet {
for characteristic in service.characteristics {
print(characteristic.characteristicType)
if characteristic.characteristicType == HMCharacteristicTypePowerState {
print(characteristic.metadata!)
dump(characteristic)
// Turning off the outlet
characteristic.writeValue(false, completionHandler: { (error: Error?) -> Void in
if error == nil {
print("Yep")
} else {
print("Nop")
}
})
}
}
}
}

日志

00000023-0000-1000-8000-0026BB765291
00000025-0000-1000-8000-0026BB765291
[%@ Format: bool, Manufacturer Description: Power State ]
- <HMCharacteristic: 0x1702c23e0> #0
- super: NSObject
00000026-0000-1000-8000-0026BB765291
E863F10A-079E-48FF-8F27-9C2605A29F52
E863F126-079E-48FF-8F27-9C2605A29F52
E863F10D-079E-48FF-8F27-9C2605A29F52
E863F10C-079E-48FF-8F27-9C2605A29F52
2017-02-07 23:19:59.725340 POS[499:100178] -[__NSDate length]: unrecognized selector sent to instance 0x170007710
2017-02-07 23:19:59.725767 POS[499:100178] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDate length]: unrecognized selector sent to instance 0x170007710'
*** First throw call stack:
(0x188a291b8 0x18746055c 0x188a30268 0x188a2d270 0x18892680c 0x1895be458 0x1895be350 0x1895be698 0x1006328f8 0x1a249ac8c 0x199674f34 0x19966c588 0x1a249d194 0x101951258 0x101951218 0x10195eaec 0x101954ce0 0x10195f088 0x101960e2c 0x101960b78 0x187abb2a0 0x187abad8c)
libc++abi.dylib: terminating with uncaught exception of type NSException

符号

2017-02-08 10:17:47.804825 POS[602:171994] -[__NSDate length]: unrecognized selector sent to instance 0x1740169c0

iZettlePayments`-[NSDictionary(Fractionized) dateForKey:]:
0x100973d88 <+0>: stp x22, x21, [sp, #-48]!
0x100973d8c <+4>: stp x20, x19, [sp, #16]
0x100973d90 <+8>: stp x29, x30, [sp, #32]
0x100973d94 <+12>: add x29, sp, #32 ; =32
0x100973d98 <+16>: mov x19, x0
0x100973d9c <+20>: nop
0x100973da0 <+24>: ldr x20, #861056 ; (void *)0x00000001ad8966b8: NSDateFormatter
0x100973da4 <+28>: nop
0x100973da8 <+32>: ldr x21, #851248 ; "izDateFormatterUsingISO8601"
0x100973dac <+36>: mov x0, x2
0x100973db0 <+40>: bl 0x1009e9b54 ; symbol stub for: objc_retain
0x100973db4 <+44>: mov x22, x0
0x100973db8 <+48>: mov x0, x20
0x100973dbc <+52>: mov x1, x21
0x100973dc0 <+56>: bl 0x1009e9b30 ; symbol stub for: objc_msgSend
0x100973dc4 <+60>: mov x29, x29
0x100973dc8 <+64>: bl 0x1009e9b78 ; symbol stub for: objc_retainAutoreleasedReturnValue
0x100973dcc <+68>: mov x20, x0
0x100973dd0 <+72>: nop
0x100973dd4 <+76>: ldr x1, #849044 ; "valueForKey:"
0x100973dd8 <+80>: mov x0, x19
0x100973ddc <+84>: mov x2, x22
0x100973de0 <+88>: bl 0x1009e9b30 ; symbol stub for: objc_msgSend
0x100973de4 <+92>: mov x19, x0
0x100973de8 <+96>: mov x0, x22
0x100973dec <+100>: bl 0x1009e9b48 ; symbol stub for: objc_release
0x100973df0 <+104>: mov x0, x19
0x100973df4 <+108>: bl 0x1009e9b78 ; symbol stub for: objc_retainAutoreleasedReturnValue
0x100973df8 <+112>: mov x19, x0
0x100973dfc <+116>: nop
0x100973e00 <+120>: ldr x1, #851168 ; "dateFromString:"
0x100973e04 <+124>: mov x0, x20
0x100973e08 <+128>: mov x2, x19
0x100973e0c <+132>: bl 0x1009e9b30 ; symbol stub for: objc_msgSend
0x100973e10 <+136>: mov x29, x29
0x100973e14 <+140>: bl 0x1009e9b78 ; symbol stub for: objc_retainAutoreleasedReturnValue
0x100973e18 <+144>: mov x21, x0
0x100973e1c <+148>: mov x0, x19
0x100973e20 <+152>: bl 0x1009e9b48 ; symbol stub for: objc_release
0x100973e24 <+156>: mov x0, x20
0x100973e28 <+160>: bl 0x1009e9b48 ; symbol stub for: objc_release
0x100973e2c <+164>: mov x0, x21
0x100973e30 <+168>: ldp x29, x30, [sp, #32]
0x100973e34 <+172>: ldp x20, x19, [sp, #16]
0x100973e38 <+176>: ldp x22, x21, [sp], #48
0x100973e3c <+180>: b 0x1009e9ac4 ; symbol stub for: objc_autoreleaseReturnValue

浏览 Elgato Eve services and characteristics , 显示数组中的第一个特征是持有名称的特征,第二个是我需要操作的特征。打印的元数据显示它是一个 bool 值,并确认它的电源状态,并且它是可读和可写的,如之前链接的表中所述。由于我对正确的特性写入了错误, socket 关闭,但几秒钟后,应用程序崩溃了。我已经删除了所有可能干扰的观察者和委托(delegate)方法。这真的让我很困惑。此外,代码不会在 iOS 9 上崩溃,仅在 iOS 10.2 和 10.3 beta 上崩溃

解决方案

抱歉,伙计们,在咒骂了一大堆之后,脚趾受伤了,头发也少了很多,24 小时后,我找到了罪魁祸首。我正在使用 iZettle,一种支付设备,一旦库被添加到项目中,它就崩溃了。 iZettle 的人承认他们对 NSDictionary 进行了扩展

@interface NSDictionary (Fractionized)
- (NSDate *)dateForKey:(id)aKey;
@end

这个与 HomeKit 中的扩展冲突,所以这就是问题的原因。结果是他们必须为其扩展添加前缀并再次编译库。

最佳答案

虽然符号化的堆栈跟踪会有所帮助,但您的日志中有一个符号可能会提供有用的提示:某些东西正在尝试向 NSDate 请求长度。根据我的经验,当库期望某个东西是 NSString 并且它即将解析它或打印它或你有什么时,就会发生这种情况。

也许你知道 NSDates 在哪里被使用。它还有助于了解崩溃是否发生在执行上述代码的同一线程上。鉴于您遇到了轻微的延迟,很难说它是否与该代码有关!也许在您的应用程序的其他地方,您正在响应设备本身为您提供状态更新,并且可能打印一个您认为是字符串但实际上是日期的值?

关于ios - HomeKit 崩溃原因 : '-[__NSDate length]: but Bool sent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42101609/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com