CPDistributedMessageCenter不工作ios7

CPDistributedMessageCenter不工作ios7,ios,notifications,messaging,jailbreak,Ios,Notifications,Messaging,Jailbreak,我对越狱iOS开发相当陌生,有一个问题。我试图在两个进程(MobileSafari到SpringBoard)之间发送消息,但遇到问题,SpringBoard中的Receiver函数从未调用过!到目前为止,在SpringBoard,我有以下几点: -(void)applicationDidFinishLaunching:(id)arg1{ %orig(arg1); //register for notifications

我对越狱iOS开发相当陌生,有一个问题。我试图在两个进程(MobileSafari到SpringBoard)之间发送消息,但遇到问题,SpringBoard中的Receiver函数从未调用过!到目前为止,在SpringBoard,我有以下几点:

    -(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
当按下MobileSafari中的按钮时,我将此代码称为:

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];
每当SpringBoard启动时,我会收到“已注册”的警报,然后当我按下按钮时,我会收到“已发送”的消息。唯一没有调用的是函数handleMessageName:withUserInfo:

为什么这不起作用

谢谢

试试darwin notifications,这是一个公共API,应该不难找到示例代码。

试试darwin notifications,这是一个公共API,应该不难找到示例代码。

如果你在iOS 7上使用
CPDistributedMessageCenter
有问题,但Ryan Petrich出版了一个图书馆,可以帮助您解决这些问题:

进程间通信 CPDistributedMessageCenter、XPC和其他构建在上面的IPC方法 引导注册的马赫数服务不起作用;你得到拒绝查找 在Xcode控制台中

解决方案
rpetrich构建了一个称为RocketBootstrap的解决方案:“进程之间相互通信的一种常见方式 在iOS和OSX上,通过一个名为mach端口的消息传递系统 端口是一个可以接收或发送消息的通道 这些端口的中央注册系统称为引导,其中 端口可以通过分配给的服务名称进行注册和访问 最新版本的iOS限制了进程可以使用的名称 仅允许访问MobileMail、MobileSafari和App Store应用程序 访问iOS附带的一组非常特定的服务。 RocketBootstrap添加了一个不限制 哪些进程可以访问哪些服务。”

如果您在iOS 7上使用
CPDistributedMessageCenter
,看起来有问题,但是Ryan Petrich发布了一个库,可以帮助您解决这些问题:

进程间通信 CPDistributedMessageCenter、XPC和其他构建在上面的IPC方法 引导注册的马赫数服务不起作用;你得到拒绝查找 在Xcode控制台中

解决方案
rpetrich构建了一个称为RocketBootstrap的解决方案:“进程之间相互通信的一种常见方式 在iOS和OSX上,通过一个名为mach端口的消息传递系统 端口是一个可以接收或发送消息的通道 这些端口的中央注册系统称为引导,其中 端口可以通过分配给的服务名称进行注册和访问 最新版本的iOS限制了进程可以使用的名称 仅允许访问MobileMail、MobileSafari和App Store应用程序 访问iOS附带的一组非常特定的服务。 RocketBootstrap添加了一个不限制 哪些进程可以访问哪些服务。”


尝试发送没有用户信息的通知。分布式通知中心通常被限制在沙盒应用程序中-您可以发送通知,但不需要用户信息。Safari是沙盒的,您的通知可能会因为用户信息而被忽略。这不起作用。还有其他想法吗?我也愿意用其他方式从MobileSafari向SpringBoard发送信息。看起来safari sandbox更加严格。总是有darwin通知,它们无处不在,但不支持用户信息。您可以尝试
CFNotificationCenterGetDistributedCenter
,包括或不包括用户信息(pass nil)。另外,使用
cpdistributedMessageCenter
时,请检查控制台。应该有消息说sandbox拒绝了你的呼叫。你能给出一个例子或链接到一些如何使用Darwin通知的代码吗?谷歌搜索没有发现任何东西。。。谢谢你的帮助!:)尝试发送没有用户信息的通知。分布式通知中心通常被限制在沙盒应用程序中-您可以发送通知,但不需要用户信息。Safari是沙盒的,您的通知可能会因为用户信息而被忽略。这不起作用。还有其他想法吗?我也愿意用其他方式从MobileSafari向SpringBoard发送信息。看起来safari sandbox更加严格。总是有darwin通知,它们无处不在,但不支持用户信息。您可以尝试
CFNotificationCenterGetDistributedCenter
,包括或不包括用户信息(pass nil)。另外,使用
cpdistributedMessageCenter
时,请检查控制台。应该有消息说sandbox拒绝了你的呼叫。你能给出一个例子或链接到一些如何使用Darwin通知的代码吗?谷歌搜索没有发现任何东西。。。谢谢你的帮助!:)