想使用rocketbootstrap实现一个主app和分身app的同步功能。通过主app发送数据给分身app,然后分身app调用app类中的方法
server端的代码,hook springboard可以接收到消息,在app中initService方法中注册监听接收不了消息是为什么?
另外我尝试使用全局变量来保存springboard接收到的数据,但是在MessengerAppDelegate中调用该变量内容却是空的。
%hook MessengerAppDelegate
- (void)initService
{
%orig;
CPDistributedMessagingCenter *c = [%c(CPDistributedMessagingCenter) centerNamed:@“com.my.check”];
rocketbootstrap_distributedmessagingcenter_apply(c);
[c runServerOnCurrentThread];
[c registerForMessageName:@“myMessageName” target:self selector:@selector(handleMessageNamed:withUserInfo:)];
NSLog(@“注册监听 start”);
}
%new
-
(void)handleMessage:(NSString *)name withUserInfo:(NSDictionary *)userInfo {
NSLog(@“handleMessage withUserInfo:%@”,userInfo);//TODO:something
}
%end
%hook SpringBoard
- (void)applicationDidFinishLaunching:(id)application {
%orig;
CPDistributedMessagingCenter *c = [%c(CPDistributedMessagingCenter) centerNamed:@“com.my.check”];
rocketbootstrap_distributedmessagingcenter_apply(c);
[c runServerOnCurrentThread];
[c registerForMessageName:@“myMessageName” target:self selector:@selector(handleMessage:withUserInfo:)];
NSLog(@“注册监听 start123123”);
}
%new
- (void)handleMessage:(NSString *)name withUserInfo:(NSDictionary *)userInfo {
//NSLog(@“handleMessage%@ withUserInfo:%@”,name, userInfo);
//TODO:something
NSLog(@“message nsParmas %@”, nsParmas);
}
%end