自定义nsusernotificativation对象



我正在尝试修改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对象涉及?

,所以这类并不意味着被覆盖,而是好消息:有一个UserInfo dict?

因此,您可以在UserInfo dict ...

中存储像KV对一样的任何对象
int theid;
NSUserNotification *notification = [[NSUserNotification alloc] init];
NSDictionary * userInfo = [NSMutableDictionary dictionary];
[userInfo setValue:@(theid) forKey:@"theid"];
notification.userInfo = userInfo;

最新更新