我对越狱的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函数:

为什么这不起作用?

谢谢!

最佳答案

尝试darwin通知https://developer.apple.com/library/mac/documentation/corefoundation/Reference/CFNotificationCenterRef/Reference/reference.html这是一个 public API,应该很容易找到示例代码。

09-15 18:12