【发布时间】:2016-02-11 13:35:29
【问题描述】:
我有一个继承自 UILocalNotification 的自定义类,它有一个 Store 对象属性(继承自 NSObject 的类):
customLocalNotification.h:
@property (strong,nonatomic) Store *store;
但是当我尝试像这样在viewController 中设置“Store”对象时:
customLocalNotification *notification=[[customLocalNotification alloc] init];
notification.store=store; //Crashes here
编辑:我将使用userInfo 字典来保存我的Store 对象,但是当我尝试这样做时,它会崩溃并显示以下错误消息:
2016-02-11 15:55:26.132 App[13861:3606796] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'unable to serialize userInfo: Error Domain=NSCocoaErrorDomain Code=3851 "Property list invalid for format: 200 (property lists cannot contain objects of type 'CFType')" UserInfo={NSDebugDescription=Property list invalid for format: 200 (property lists cannot contain objects of type 'CFType')}'
*** First throw call stack:
(
0 CoreFoundation 0x000000010c196e65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010bc0fdeb objc_exception_throw + 48
2 UIKit 0x000000010cbd5ba5 -[UIConcreteLocalNotification userInfo] + 0
3 App 0x00000001088cb65b -[monitorLocationViewController createNotificationWithStore:andArounders:] + 683
4 App 0x00000001088cb1ed -[monitorLocationViewController sendNotificationIfNeededForStore:] + 397
5 App 0x00000001088cb021 -[monitorLocationViewController locationManager:didEnterRegion:] + 145
6 App 0x00000001088cae9c __68-[monitorLocationViewController locationManager:didUpdateLocations:]_block_invoke + 284
7 CoreFoundation 0x000000010c0f59ff __51-[__NSSetM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 79
8 CoreFoundation 0x000000010c0f590a -[__NSSetM enumerateObjectsWithOptions:usingBlock:] + 202
9 App 0x00000001088cad02 -[monitorLocationViewController locationManager:didUpdateLocations:] + 402
10 CoreLocation 0x000000010a8c5177 CLClientGetCapabilities + 20882
11 CoreLocation 0x000000010a8c15d3 CLClientGetCapabilities + 5614
12 CoreLocation 0x000000010a8bc0cd CLClientInvalidate + 923
13 CoreFoundation 0x000000010c0c2a1c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
14 CoreFoundation 0x000000010c0b86a5 __CFRunLoopDoBlocks + 341
15 CoreFoundation 0x000000010c0b7e02 __CFRunLoopRun + 850
16 CoreFoundation 0x000000010c0b7828 CFRunLoopRunSpecific + 488
17 GraphicsServices 0x000000010ed92ad2 GSEventRunModal + 161
18 UIKit 0x000000010c543610 UIApplicationMain + 171
19 App 0x00000001088dedef main + 111
20 libdyld.dylib 0x000000010dbbe92d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
有人知道为什么会崩溃吗?
谢谢!
【问题讨论】:
-
不知何故你没有得到
UILocalNotification的子类。你的init方法是什么样的? -
顺便说一句,以其他方式存储附加属性可能更有意义。
UILocalNotification对象被传递给 iOS,而您的自定义类可能无法在转换过程中存活。 -
@Avi 我不会在
customLocalNotification上覆盖init,所以我猜这是默认设置。 -
@Avi 如何在没有自定义类的情况下将商店属性存储到
UILocalNotification对象? -
看来你不能真正继承
UILocalNotification,它的类永远是UIConcreteLocationNotification。我从UILocalNotification继承然后从UIView对其进行了测试,并且它的类不会因从UILocalNotification继承而改变。您可能还对stackoverflow.com/questions/8580782/… 感兴趣,您可能还希望将自定义数据放入userInfo(NSDictionary) 以用于您未知的目的...
标签: ios objective-c cocoa-touch unrecognized-selector