IOS逆向--Tweak和app交互方案【进程通信】

来源:互联网 发布:淘宝的隐藏优惠券插件 编辑:程序博客网 时间:2024/06/15 01:11

Tweak端:

CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),                                        NULL,                                        &NotificationReceivedCallback,                                        CFSTR("com.chinapyg.fakecarrier-change"),                                        NULL,                                        CFNotificationSuspensionBehaviorCoalesce);// 回调:static void NotificationReceivedCallback(CFNotificationCenterRef center,                                         void *observer, CFStringRef name,                                         const void *object, CFDictionaryRef                                         userInfo){//....  可以根据 name来判断是何种消息,下面的客户端传了NULL,所以无需判断了,在多种消息的时候需要用到}

APP端:

1.一句代码即可

notify_post("com.chinapyg.fakecarrier-change");

2.复杂点的

CFStringRef observedObject =            CFSTR("com.chinapyg.fakecarrier-change");CFNotificationCenterRef center =            CFNotificationCenterGetDistributedCenter();CFNotificationCenterPostNotification(center, NULL,            observedObject, NULL /* no dictionary */, TRUE);
  • 接收端(后台):
NSString *observedObject = @"com.chinapyg.notification";// 处理单个计算机上不同的进程之间的通知NSDistributedNotificationCenter *center =            [NSDistributedNotificationCenter defaultCenter];[center addObserver: self            selector: @selector(callbackWithNotification:)            name: @"PiaoYun Notification"            object: observedObject];// 回调:- (void)callbackWithNotification:(NSNotification *)myNotification;{        NSLog(@"Notification Received");}
  • 发送端(app):
NSString *observedObject = @"com.mycompany.notification";NSDistributedNotificationCenter *center =            [NSDistributedNotificationCenter defaultCenter];[center postNotificationName: @"PiaoYun Notification"            object: observedObject            userInfo: nil /* no dictionary */            deliverImmediately: YES];

iOS上层接口:

// 处理单进程之间的通知[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(callBack) name: @"back" object: nil];// 回调- (void)callBack{                NSLog(@"Notification Received");}//发出通知        [[NSNotificationCenter defaultCenter] postNotificationName:@"back" object:self];
原创粉丝点击