简体   繁体   English

关于Apple Watch应用程序上的本地通知

[英]About local notifications on Apple watch app

I have managed scheduling local notification on ios app and have tested them on static notifications interface on apple watch. 我已经在iOS应用上管理了计划本地通知,并在Apple Watch的静态通知界面上对其进行了测试。 But, there is a glitch (maybe not?) with that, static local notification interface is being displayed even when the watch app is still running ie on the foreground (iphone app is backgrounded and iphone is locked). 但是,有一个小故障(可能不是吗?),即使手表应用仍在运行,即在前台(iphone应用为后台且iphone被锁定),仍会显示静态本地通知界面。 Also when watch app is active, iphone app is backgrounded, and iphone is NOT locked, iphone is displaying the notification. 同样,当手表应用程序处于活动状态,iphone应用程序处于后台并且iphone未锁定时,iphone会显示通知。 This is really weird to me. 这对我来说真的很奇怪。

I'm scheduling local notification as below: 我正在安排本地通知,如下所示:

NSString *textToShow = nil;
        NSSet *categories = nil;
        textToShow = text;
        UIMutableUserNotificationAction *notificationAction1 = [[UIMutableUserNotificationAction alloc] init];
        notificationAction1.identifier = @"openWKApp";
        notificationAction1.title = localStr(@"View");
        notificationAction1.activationMode = UIUserNotificationActivationModeForeground;
        notificationAction1.destructive = NO;
        notificationAction1.authenticationRequired = NO;

        UIMutableUserNotificationCategory *notificationCategory = [[UIMutableUserNotificationCategory alloc] init];
        notificationCategory.identifier = @"openWKApp";
        [notificationCategory setActions:@[notificationAction1] forContext:UIUserNotificationActionContextDefault];
        [notificationCategory setActions:@[notificationAction1] forContext:UIUserNotificationActionContextMinimal];
        categories = [NSSet setWithObjects:notificationCategory, nil];

        UIUserNotificationType notificationType = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
        UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:notificationType categories:categories];

        [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];

        UILocalNotification *localNotification = [[UILocalNotification alloc] init];
        localNotification.fireDate = date;

        localNotification.alertBody = @"Notification body";

        localNotification.applicationIconBadgeNumber = 1;
        localNotification.userInfo = info;
        localNotification.category = @"openWKApp";

        localNotification.soundName = UILocalNotificationDefaultSoundName;

        [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

If anybody has faced the same and fixed or found the way around, please, help! 如果有人面临相同的问题并已解决或找到解决方法,请提供帮助!

Ended up canceling notifications on willActivate , and re-scheduling on didDeactivate of watchkit. 最终在willActivate上取消了通知,并在didDeactivate的didDeactivate上重新安排了时间。 Still, it's really weird to receive notification when watchkit app is running. 不过,当watchkit应用程序运行时收到通知确实很奇怪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM