关于Apple watch app

时间:2015-07-29 12:55:02

标签: ios uilocalnotification watchkit

我已在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];

如果有人面对同样的问题并修复或找到了解决方法,请帮助!

1 个答案:

答案 0 :(得分:0)

结束取消willActivate上的通知,并重新安排didDeactivate的watchkit。但是,当watchkit应用程序运行时收到通知真的很奇怪。