简体   繁体   English

CPDistributedMessagingCenter无法正常工作的iOS7

[英]CPDistributedMessagingCenter not working ios7

I am fairly new to jailbreak iOS development and had a question. 我对越狱的iOS开发相当陌生,并且有一个问题。 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! 我正在尝试在两个进程(从MobileSafari到SpringBoard)之间发送消息,并且遇到问题,从未调用SpringBoard中的接收器功能! So far in SpringBoard I have this: 到目前为止,在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

and when a button is pressed in MobileSafari I call this code: 当在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];

I get the alert "registered" whenever SpringBoard starts up and then when I press the button I get the message "sent". 每当SpringBoard启动时,我都会收到警报“已注册”,然后当我按下按钮时,我会收到消息“已发送”。 The only thing that isn't called is the function handleMessageNamed:withUserInfo: 唯一没有被调用的就是handleMessageNamed:withUserInfo函数:

Why isn't this working? 为什么这不起作用?

Thanks! 谢谢!

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

Inter-process communication 进程间通讯

CPDistributedMessagingCenter, XPC and other IPC methods built on top of bootstrap registered mach services don't work; 建立在引导注册的Mach服务之上的CPDistributedMessagingCenter,XPC和其他IPC方法不起作用; you get deny lookup in the Xcode console. 您会在Xcode控制台中拒绝查找。

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." 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