0
我花了很多時間測試通知,並且無法將它們顯示在Apple Watch上。我可以收到來自其他應用的通知 - 我的手錶已配對,Do Disturbe已禁用。本地推送通知顯示在我的iPhone上,但不顯示在Apple Watch上。 iPhone屏幕在通知到達時被鎖定。Apple Watch上不顯示本地推送通知
我做如下:
1.請求允許
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];
}
其在iPhone上工作,你是什麼意思? –
@balkaransingh是 –
該應用是否安裝在手錶上?你有通知用戶界面嗎? – jrturton