2016-07-22 57 views
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]; 
} 

Screenshot of iPhone Lock Screen with the notification. Notifications has 2 actions

+0

其在iPhone上工作,你是什麼意思? –

+0

@balkaransingh是 –

+0

該應用是否安裝在手錶上?你有通知用戶界面嗎? – jrturton

回答

0

我在監視應用程序啓用通知解決我的問題:

  1. 在iPhone上打開Watch應用程序,點擊My Watch選項卡,然後點擊Not ifications。
  2. 點按一個應用程序。

來源:https://support.apple.com/en-us/HT204791