3

我已经设置了本地通知,如下所示:

-(void)startLocalNotification 
{

    UILocalNotification *notification = [[UILocalNotification alloc] init];
    notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:7];
    notification.alertBody = @"This is local notification!";
    notification.timeZone = [NSTimeZone defaultTimeZone];
    notification.soundName = UILocalNotificationDefaultSoundName;
    notification.applicationIconBadgeNumber = 10;
    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"Hello! This is Local Notification!" forKey:@"Notification"];
    notification.userInfo = infoDict;
    [[UIApplication sharedApplication] scheduleLocalNotification:notification];
}

我在 iPhone 模拟器上收到了通知。但它不会触发 watchkit 应用程序的通知。我在 watchkit 扩展中的 NotificationController.m 中使用以下方法-

- (void)didReceiveLocalNotification:(UILocalNotification *)localNotification withCompletion:(void (^)(WKUserNotificationInterfaceType))completionHandler
{
     NSLog(@"Notification Received ..");
    completionHandler(WKUserNotificationInterfaceTypeCustom);

}

谁能告诉我为什么我没有在 watchkit App 中收到本地通知。

提前致谢。

4

1 回答 1

4

在此处查看 Apple Watch 编程指南

When one of your app’s local or remote notifications arrives on the user’s iPhone, iOS decides whether to display that notification on the iPhone or on the Apple Watch.

因此,您无需担心在 Watch 上发送通知,iOS 会为您完成。

无论如何,如果您只想在手表上发送通知,您可以使用Darwin Notification Concepts,但请记住有一些限制,您可以查看给定的链接。

您还可以使用共享容器在 App 和扩展程序之间进行通信。

希望它会帮助你。

于 2015-04-08T12:38:49.480 回答