【发布时间】:2015-10-14 18:05:11
【问题描述】:
我开发了一个 Apple Watch 应用程序。我想要一个简单的行为:当我在配对手表应用程序上按下 iPhone 上的按钮时,我想出现一个通知。这可能吗? 我使用 watch OS 2,我的手表应用程序与 iPhone 应用程序完美通信,反之亦然,通过 WatchConectivity。 所以使用 WCSession 我可以通知手表应用程序,但我如何以通知样式显示控制器,我的意思是这样
我看到在继承自 WKUserNotificationInterfaceController 的控制器上存在
- (void)didReceiveLocalNotification:(UILocalNotification *)localNotification withCompletion:(void (^)(WKUserNotificationInterfaceType))completionHandler {
我怎样才能让这个方法被调用?我试着在手表上创建一个 UILocalNotification
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.category = @"myCategory";
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:8];
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];
问题是手表中不存在 UIApplication 所以我无法安排通知。我在 iOS 应用程序上做了同样的事情,但在这种情况下,我在 iPhone 上收到了通知。 我不得不说,在手表应用程序上存在一个类别名称为“myCategory”的 NotificationInterfaceController。
谢谢!
【问题讨论】:
标签: notifications apple-push-notifications watchkit