如何從你的一個App發送通知給另一個App? (例:搜狗IME下載皮膚完成後使用皮膚) 註:搜狗IME是App、而鍵盤是Extension
當你為你的App 添加 App Extension時,如果想在App 發送通知給 Extension或許這篇文章可以協助你。
瞭解更多內容
// 發送通知- (void)postNotificaiton {CFNotificationCenterRef notification = CFNotificationCenterGetDarwinNotifyCenter ();CFNotificationCenterPostNotification(notification, CFSTR("<notificaiton name>"), NULL,NULL, YES);} // 接收通知- (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 } // 移除通知- (void)removeNotification{CFNotificationCenterRef notification = CFNotificationCenterGetDarwinNotifyCenter ();CFNotificationCenterRemoveObserver(notification, (__bridge const void *)(self), CFSTR("<notificaiton name>"), NULL);}
以上內容給大家簡單介紹了IOS如何在Host App 與 App Extension 之間發送通知的相關內容,希望對大家有所協助!