我正在谷歌搜索以找出在WatchOS模拟器上查看本地通知的方法因为我没有iWatch。现在我已经实现了本地通知,但由于某种原因通知在iPhone模拟器上显示,但在iWatch(WatchOS 2)模拟器上没有。
我在applicationDidFinishLaunchingWithOptions:
UIMutableUserNotificationAction *action1;
action1 = [[UIMutableUserNotificationAction alloc] init];
[action1 setActivationMode:UIUserNotificationActivationModeBackground];
[action1 setTitle:@"Action 1"];
[action1 setIdentifier:kAction1];
[action1 setDestructive:NO];
[action1 setAuthenticationRequired:NO];
UIMutableUserNotificationAction *action2;
action2 = [[UIMutableUserNotificationAction alloc] init];
[action2 setActivationMode:UIUserNotificationActivationModeBackground];
[action2 setTitle:@"Action 2"];
[action2 setIdentifier:kAction2];
[action2 setDestructive:NO];
[action2 setAuthenticationRequired:NO];
UIMutableUserNotificationCategory *actionCategory;
actionCategory = [[UIMutableUserNotificationCategory alloc] init];
[actionCategory setIdentifier:kAction3];
[actionCategory setActions:@[action1, action2]
forContext:UIUserNotificationActionContextDefault];
NSSet *categories = [NSSet setWithObject:actionCategory];
UIUserNotificationType types = (UIUserNotificationTypeAlert|
UIUserNotificationTypeSound|
UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings;
settings = [UIUserNotificationSettings settingsForTypes:types
categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
您是否能够在模拟器中收到WatchOS本地通知的通知?
答案 0 :(得分:2)
在模拟器上运行您的观看应用,从iPhone
模拟器安排notification
并锁定iPhone
模拟器屏幕,保持手表模拟器处于活动状态,在这种情况下触发通知时,将在您的watch
模拟器上发布。当您在实际设备上进行测试时也是如此。
答案 1 :(得分:0)
Watch应用程序模拟器无法对UILocalNotification做出反应。但是,除了通过几种不同的方法进行路由之外,它几乎与对推送通知做出反应相同。
以下答案将有所帮助: 资料来源:https://stackoverflow.com/a/27278093/2798877