我已经设置本地通知如下:
-(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 应用程序中收不到本地通知。
提前致谢。
最佳答案
参见 Apple Watch 编程指南 HERE
当您应用的本地或远程通知之一到达用户的 iPhone 时,iOS 会决定是在 iPhone 上还是在 Apple Watch 上显示该通知。
因此您无需担心在 Watch 上发送通知,iOS 会为您完成。
无论如何,如果你只想在 watch 上发送通知,你可以使用 Darwin Notification Concepts ,但请记住存在一些限制,您可以查看给定的链接。
您还可以使用 shared container用于应用程序和扩展程序之间的通信。
希望对你有所帮助。
关于ios - 在 watchkit 中接收本地通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29513301/