1

我正在尝试修改 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对象会卷入其中?

4

1 回答 1

2

所以这个类似乎并不意味着被覆盖,但好消息是:有一个userInfo字典?

因此,您可以将任何对象作为 KV 对存储在 userInfo 字典中...

int theid;
NSUserNotification *notification = [[NSUserNotification alloc] init];
NSDictionary * userInfo = [NSMutableDictionary dictionary];
[userInfo setValue:@(theid) forKey:@"theid"];
notification.userInfo = userInfo;
于 2016-12-21T14:27:17.337 回答