How does IOS send notifications between Host App and App Extension

  • 2020-05-19 05:58:20
  • OfStack

How do I send notifications from one App to another App? Note: sogou input method is App, while the keyboard is Extension

When you add App Extension to your App, this article may help you if you want to send a notification to Extension at App.

Learn more


//  Send a notification 
- (void)postNotificaiton {
CFNotificationCenterRef notification = CFNotificationCenterGetDarwinNotifyCenter ();
CFNotificationCenterPostNotification(notification, CFSTR("<notificaiton name>"), NULL,NULL, YES);
} 
//  Receive notifications 
- (void)receiveNotification {
CFNotificationCenterRef notification = CFNotificationCenterGetDarwinNotifyCenter (); 
CFNotificationCenterAddObserver(notification, (__bridge const void *)(self), observerMethod,CFSTR("<notificaiton name>"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately); 
}
void observerMethod (CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{ 
// Your custom work 
} 
//  Remove the notification 
- (void)removeNotification
{
CFNotificationCenterRef notification = CFNotificationCenterGetDarwinNotifyCenter ();
CFNotificationCenterRemoveObserver(notification, (__bridge const void *)(self), CFSTR("<notificaiton name>"), NULL);
}

The above content gives you a brief introduction of IOS how to send notifications between Host App and App Extension. I hope it will be helpful to you!


Related articles: