【问题标题】:About local notifications on Apple watch app关于 Apple Watch 应用上的本地通知
【发布时间】:2015-07-29 12:55:01
【问题描述】:

我已经在 ios 应用程序上安排了本地通知,并在 Apple Watch 上的静态通知界面上对其进行了测试。但是,有一个小故障(也许不是?),即使手表应用程序仍在运行,即在前台(iphone 应用程序在后台并且 iphone 被锁定),也会显示静态本地通知界面。此外,当手表应用程序处于活动状态时,iphone 应用程序在后台运行,并且 iphone 未锁定,iphone 正在显示通知。这对我来说真的很奇怪。

我正在安排本地通知如下:

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];

如果有人遇到过同样的情况并修复或找到解决方法,请帮忙!

【问题讨论】:

    标签: ios uilocalnotification watchkit


    【解决方案1】:

    最终取消了willActivate 上的通知,并在 watchkit 的didDeactivate 上重新安排了时间。不过,当 watchkit 应用程序运行时收到通知真的很奇怪。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-05
      • 1970-01-01
      • 1970-01-01
      • 2015-01-27
      相关资源
      最近更新 更多