Я пытаюсь отправить уведомление от моего iPhone к устройству Watch, используя CFNotificationCenterAddObserver
на часы и CFNotificationCenterPostNotification
. (Я НЕ тестирование на Xcode тренажере).WatchKit Уведомление Дарвин не получил на часы
Это мой код в приложение IOS:
#include <CoreFoundation/CoreFoundation.h>
...
- (void)sendLogOutNotificationToWatch{
dispatch_async(dispatch_get_main_queue(), ^{
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("NOTIFICATION_TO_WATCH"), (__bridge const void *)(self), nil, TRUE);
});
}
И это, как я использую его на приложение яблоко расширения часы:
@implementation InterfaceController
.....
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
....
[self registerToNotification];
}
- (void)registerToNotification
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:@com.test.app" object:nil];
CFNotificationCenterRemoveObserver(CFNotificationCenterGetDarwinNotifyCenter(), (__bridge const void *)(self), CFSTR("NOTIFICATION_TO_WATCH"), NULL);
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userLoggedOut) name:@"com.test.app" object:nil];
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), (__bridge const void *)(self), didReceivedDarwinNotification, CFSTR("NOTIFICATION_TO_WATCH"), NULL, CFNotificationSuspensionBehaviorDrop);
}
void didReceivedDarwinNotification()
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"com.test.app" object:nil];
}
- (void)didDeactivate {
[super didDeactivate];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"com.test.app" object:nil];
CFNotificationCenterRemoveObserver(CFNotificationCenterGetDarwinNotifyCenter(), (__bridge const void *)(self), CFSTR("NOTIFICATION_TO_WATCH"), NULL);
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)userLoggedOut{
[self showAlertViewwithTitle:@"Notice" andMessage:@"User logged out on iPhone device!"];
}
Вы не можете использовать центр уведомлений darwin для отправки сообщений в watchos2, используя фреймворк 'WatchConnectivity' – dan
, который уже использует его для отправки сообщений с часов на iPhone, но как я могу использовать его наоборот? –