我可以在WatchOS 2模拟器上测试本地通知吗?

时间:2016-02-08 20:06:52

标签: ios iphone uilocalnotification watch-os-2 watchos-simulator

我正在谷歌搜索以找出在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本地通知的通知?

2 个答案:

答案 0 :(得分:2)

在模拟器上运行您的观看应用,从iPhone模拟器安排notification并锁定iPhone模拟器屏幕,保持手表模拟器处于活动状态,在这种情况下触发通知时,将在您的watch模拟器上发布。当您在实际设备上进行测试时也是如此。

答案 1 :(得分:0)

Watch应用程序模拟器无法对UILocalNotification做出反应。但是,除了通过几种不同的方法进行路由之外,它几乎与对推送通知做出反应相同。

以下答案将有所帮助: 资料来源:https://stackoverflow.com/a/27278093/2798877