繁体   English   中英

CPDistributedMessagingCenter无法正常工作的iOS7

[英]CPDistributedMessagingCenter not working ios7

我对越狱的iOS开发相当陌生,并且有一个问题。 我正在尝试在两个进程(从MobileSafari到SpringBoard)之间发送消息,并且遇到问题,从未调用SpringBoard中的接收器功能! 到目前为止,在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启动时,我都会收到警报“已注册”,然后当我按下按钮时,我会收到消息“已发送”。 唯一没有被调用的就是handleMessageNamed:withUserInfo函数:

为什么这不起作用?

谢谢!

如果您查看标题为“更新iOS 7的扩展”的文档 ,则可能 CPDistributedMessagingCenter在iOS 7上使用CPDistributedMessagingCenter存在问题,但是Ryan Petrich发布了一个库,可以帮助您解决这些问题:

进程间通讯

建立在引导注册的Mach服务之上的CPDistributedMessagingCenter,XPC和其他IPC方法不起作用; 您会在Xcode控制台中拒绝查找。

解决方法
rpetrich建立了一个称为RocketBootstrap的变通方法:“进程在iOS和OS X上相互通信的一种常见方式是通过称为mach端口的消息传递系统。每个端口都是一个可以接收或发送消息的通道。有一个中央注册系统。对于这些称为引导程序的端口,可以通过为其分配的服务名称来注册和访问端口。iOS的最新版本限制了进程可以访问的名称-仅允许MobileMail,MobileSafari和App Store应用访问一组特定的iOS附带的服务。RocketBootstrap添加了辅助查找服务,该服务不限制哪些进程可以访问哪些服务。”

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM