[英]Local push notifications do not appear on Apple Watch
I spent a lot of time testing notifications and I can't make them appear on my Apple Watch. 我花了很多时间来测试通知,但无法使它们出现在Apple Watch上。 I can receive notifications from other apps - my watch is paired, Do Not Disturbe is disabled. 我可以从其他应用程序收到通知-我的手表已配对,“请勿打扰”已禁用。 Local push notifications appear on my iPhone but not on the Apple Watch. 本地推送通知显示在我的iPhone上,而不显示在Apple Watch上。 iPhone screen is locked when notification arrives. 通知到达时,iPhone屏幕被锁定。
I am doing following: 我正在执行以下操作:
1. Asking permission 1.寻求许可
2. Scheduling notification 2.安排通知
+ (void)requestPermission {
UIMutableUserNotificationAction *smallCupAction = [UIMutableUserNotificationAction new];
smallCupAction.title = NSLocalizedString(@"250 mL", @"Notification button");
smallCupAction.identifier = @"add small";
smallCupAction.activationMode = UIUserNotificationActivationModeBackground;
smallCupAction.authenticationRequired = NO;
UIMutableUserNotificationAction *mediumCupAction = [UIMutableUserNotificationAction new];
mediumCupAction.title = NSLocalizedString(@"350 mL", @"Notification button");
mediumCupAction.identifier = @"add medium";
mediumCupAction.activationMode = UIUserNotificationActivationModeBackground;
mediumCupAction.authenticationRequired = NO;
UIMutableUserNotificationAction *largeCupAction = [UIMutableUserNotificationAction new];
largeCupAction.title = NSLocalizedString(@"500 mL", @"Notification button");
largeCupAction.identifier = @"add large";
largeCupAction.activationMode = UIUserNotificationActivationModeBackground;
largeCupAction.authenticationRequired = NO;
UIMutableUserNotificationCategory *waterReminderCategoryDefault = [UIMutableUserNotificationCategory new];
[waterReminderCategoryDefault setActions:@[smallCupAction, mediumCupAction, largeCupAction] forContext:UIUserNotificationActionContextDefault];
waterReminderCategoryDefault.identifier = @"water reminder default";
NSSet *categories = [NSSet setWithObjects: waterReminderCategoryDefault, nil];
UIUserNotificationType types = (UIUserNotificationType) (UIUserNotificationTypeBadge |
UIUserNotificationTypeSound | UIUserNotificationTypeAlert);
UIUserNotificationSettings *mySettings =
[UIUserNotificationSettings settingsForTypes:types categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
}
+ (void)scheduleNotificationWithGender:(NSNumber *)gender date:(NSDate *)date {
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = date;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertBody = // localized text
localNotif.alertAction = // localized text
localNotif.alertTitle = // localized text
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;
localNotif.category = @"water reminder default";
NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:gender, kGenderKey, nil];
localNotif.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
I solved my problem by enabling notifications in the Watch app: 我通过在Watch应用中启用通知来解决了我的问题:
Source: https://support.apple.com/en-us/HT204791 资料来源: https : //support.apple.com/en-us/HT204791
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.