“无法识别的选择器已发送到实例”属性设置器

时间:2016-02-11 13:35:29

标签: ios objective-c cocoa-touch unrecognized-selector

我有一个继承自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

有谁知道为什么会崩溃?

谢谢!

2 个答案:

答案 0 :(得分:1)

UILocalNotifications旨在包含一些轻量级数据。也就是说,userInfo只能包含property list encodable项。而且我要补充的是,整个事情并不是为了抛弃重物,而只是传递一些上下文信息,你需要在它到达时处理通知(即一些标识符,数字等)。

答案 1 :(得分:0)

我同意Eiko的观点。 您可以向此字典添加任意键值对。但是,键和值必须是有效的属性列表类型;如果没有,则引发异常。 检查以下两个链接   UILocalNotification Valid Property list types

要解决您的问题,您可以试试这个 1)为您的对象存储创建NSDictionary,并将所有属性作为键值对,您希望通过UILocalNotification传递 2)设置字典对象userinfo字典
3)解析并加载新词典,并在要使用它的地方创建Store对象。