我正在尝试修改NSUserNotifictation以传递自定义变量:
@interface MyUserNotification: NSUserNotification
@property (nonatomic) int theid;
@property (nonatomic) NSString* url;
@end
@implementation MyUserNotification
@end
然后在我的AppDelegate
对象中启动时:
MyUserNotification *notification = [[MyUserNotification alloc] init];
notification.theid = theid;
设置theid
会引发错误:
-[_NSConcreteUserNotification setTheid:]: unrecognized selector sent to instance 0x100204840
为什么NSConcreteUserNotification
对象会涉及?
答案 0 :(得分:2)
所以这堂课似乎并没有被覆盖,但好消息是:有一个userInfo字典?
所以你可以在userInfo dict中存储任何对象作为KV对...
int theid;
NSUserNotification *notification = [[NSUserNotification alloc] init];
NSDictionary * userInfo = [NSMutableDictionary dictionary];
[userInfo setValue:@(theid) forKey:@"theid"];
notification.userInfo = userInfo;