【问题标题】:Can I test local notifications on the WatchOS 2 Simulator?我可以在 WatchOS 2 模拟器上测试本地通知吗?
【发布时间】:2016-02-08 20:06:52
【问题描述】:

因为我没有 iWatch,所以我在谷歌上搜索了很多以找到在 WatchOS 模拟器上查看本地通知的方法。现在我已经实现了本地通知,但由于某种原因,通知显示在 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 本地通知的通知?

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      不可能让 Watch 应用模拟器对 UILocalNotification 做出反应。但是,它几乎与对推送通知的反应相同,只是它通过几种不同的方法进行路由。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-04-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-06
        • 2018-12-27
        • 2021-04-03
        相关资源
        最近更新 更多