如何從你的一個App發送通知給另一個App? (例:搜狗輸入法下載皮膚完成後使用皮膚) 注:搜狗輸入法是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 之間發送通知的相關內容,希望對大家有所幫助!