簡體   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