How to communicate between applications in iOS?

别等时光非礼了梦想. 提交于 2019-12-04 21:46:13

try CFNotificationCenter using CFNotificationCenterGetDarwinNotifyCenter

#include <CoreFoundation/CFNotificationCenter.h>

/* This function will be called whatever a notification posted with the specified name */
void NotificationCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo){

}

void addObserver(){
    CFStringRef name = CFSTR("NotificationName");
    CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),&NotificationCallback,name,NULL,CFNotificationSuspensionBehaviorDeliverImmediately);
}

This will listen to notifications named NotificationName

To post a notification

void postNotification(){
    CFStringRef name = CFSTR("NotificationName");
    /* You have to create the userInfo dictionary and add all the keys to it */
    CFDictionaryRef userInfo;
    CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), name, NULL, userInfo, true);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!