Try darwin notifications https://developer.apple.com/library/mac/documentation/corefoundation/Reference/CFNotificationCenterRef/Reference/reference.html It's a public API, shouldn't be hard to find sample code.
CPDistributedMessagingCenter not working ios7
-
06-07-2023 - |
Question
I am fairly new to jailbreak iOS development and had a question. I am trying to send a message between two processes(MobileSafari to SpringBoard) and am having a problem, the reciever function in SpringBoard is never called! So far in SpringBoard I have this:
-(void)applicationDidFinishLaunching:(id)arg1{
%orig(arg1);
//register for notifications
CPDistributedMessagingCenter *messagingCenter = [CPDistributedMessagingCenter centerNamed:@"com.magnusdevelopment.flow"];
[messagingCenter runServerOnCurrentThread];
[messagingCenter registerForMessageName:@"updateWallpaper" target:self selector:@selector(handleMessageNamed:withUserInfo:)];
[messagingCenter registerForMessageName:@"updateScalingMode" target:self selector:@selector(handleMessageNamed:withUserInfo:)];
[messagingCenter registerForMessageName:@"downloadWallpaper" target:self selector:@selector(handleMessageNamed:withUserInfo:)];
UIAlertView *testAlert = [[UIAlertView alloc] initWithTitle:@"Yo!" message:@"registered" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[testAlert show];
}
}
%new
-(NSDictionary *)handleMessageNamed:(NSString *)name withUserInfo:(NSDictionary *)userInfo{
UIAlertView *testAlert = [[UIAlertView alloc] initWithTitle:@"Yo!" message:@"2" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[testAlert show];
if([name isEqualToString:@"updateWallpaper"]){
//get info for wallpaper
NSString *wallpaperImagePath = [userInfo objectForKey:@"WALLPAPER_PATH"];
int option = [[userInfo objectForKey:@"OPTION"] intValue];
BOOL retValue = setWallpaperImage(wallpaperImagePath, option);
//return the dictionary
NSMutableDictionary *replyDict = [[NSMutableDictionary alloc] init];
[replyDict setObject:[NSString stringWithFormat:@"%hhd",retValue] forKey:@"RETURN_VALUE"];
return replyDict;
}else if([name isEqualToString:@"updateScalingMode"]){
//get info from dictionary
int option = [[userInfo objectForKey:@"OPTION"] intValue];
NSString *scalingMode = [userInfo objectForKey:@"SCALING_MODE"];
//set wallpaper scaling mode
setWallpaperScalingMode(scalingMode,option);
}//end if
return nil;
}//end method
and when a button is pressed in MobileSafari I call this code:
NSString *option = [NSString stringWithFormat:@"%i",wallpaperOption];
NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys: wallpaperPath, @"WALLPAPER_PATH", option, @"OPTION", nil];
CPDistributedMessagingCenter *messagingCenter = [CPDistributedMessagingCenter centerNamed:@"com.magnusdevelopment.flow"];
[messagingCenter sendMessageAndReceiveReplyName:@"downloadWallpaper" userInfo:infoDict];
UIAlertView *testAlert = [[UIAlertView alloc] initWithTitle:@"Yo!" message:@"sent" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[testAlert show];
I get the alert "registered" whenever SpringBoard starts up and then when I press the button I get the message "sent". The only thing that isn't called is the function handleMessageNamed:withUserInfo:
Why isn't this working?
Thanks!
La solution
Autres conseils
If you look at this document entitled "Updating extensions for iOS 7, it looks there are problems using CPDistributedMessagingCenter
on iOS 7, but Ryan Petrich has published a library that may help you work around them:
Inter-process communication
CPDistributedMessagingCenter, XPC and other IPC methods built on top of bootstrap registered mach services don't work; you get deny lookup in the Xcode console.
Workaround:
rpetrich has built a workaround called RocketBootstrap: "One common way processes communicate with each other on iOS and OS X is through a messaging system called mach ports. Each port is a channel that can either receive or send messages. There is a central registration system for these ports called bootstrap, where ports can be registered and accessed by a service name assigned to them. Recent versions of iOS restrict which names a process can access—MobileMail, MobileSafari and App Store apps are only allowed to access a very specific set of services that come with iOS. RocketBootstrap adds a secondary lookup service that doesn't restrict which processes can access which services."