【发布时间】: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