Can I test local notifications on the WatchOS 2 Simulator?

526 views Asked by At

I am Googling a lot to find out way to check local notifications on the WatchOS Simulator because I don't have an iWatch. Right now I have implemented local notification but due some reason notification is shown on iPhone simulator but not on iWatch (WatchOS 2) simulator.

I have added following code in 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];

Have you been able to get notifications for WatchOS local notifications in the simulator?

2

There are 2 answers

0
Muneeba On BEST ANSWER

Run your watch app on simulator, from iPhone simulator schedule the notification and lock the iPhone simulator screen, keep the watch simulator active, in that case when notification is triggered , it will be delivered on your watch simulator. Same will be the case when you will test on actual devices.

0
Deepak Carpenter On

It is not possible to have a Watch app simulator react to a UILocalNotification. However, it is almost identical to reacting to a push notification, except it gets routed through a couple of different methods.

below answer will be helpful: Source : https://stackoverflow.com/a/27278093/2798877