2015-01-23 6 views
0

CFMessagePort을 사용하기 전에 iOS7 이상에서는 사용할 수 없지만 교체 된 방법이 있습니까? 나는 의 생성자를 hooking 할 때 CFMessagePort을 시도했지만, 대부분의 어플리케이션에서는 성공적으로 CFMessagePortCreateLocal을 리턴 할 수 없다. 단지 NULL을 반환한다. 나는 어딘가 잘못인가?iOS에서 응용 프로그램 간의 통신 방법은 무엇입니까?

static void setupUIApplicationMessagePort() 
{ 
    NSString *identifier = @"com.foo.foo.UIApplication"; 
    CFMessagePortRef local = CFMessagePortCreateLocal(NULL, (__bridge CFStringRef)identifier, callBackForUIApplication, NULL, NULL); 
    if (local) { 
     NSLog(@"local OK: %@", local); 

     CFRunLoopSourceRef source = CFMessagePortCreateRunLoopSource(NULL, local, 0); 
     CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopCommonModes); 
     rocketbootstrap_cfmessageportexposelocal(local); 
    } else { 
     NSLog(@"local is NULL"); // in most of the apps it returns NULL 
    } 
} 

%ctor { 
    if(%c(UIApplication)) { 
     setupUIApplicationMessagePort(); 
    } 
} 
+0

가능한 [App 그룹과 앱 간 데이터 통신 및 지속] (http://stackoverflow.com/questions/24015506/communicating-and-persisting-data-between-apps-with-app-groups) – TCB13

+0

URL : https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Inter-AppCommunication/Inter-AppCommunication.html – TCB13

+0

이것은 탈옥 질문이므로 저수준 API가 필요합니다. – creker

답변

2

이 알림을 게시하려면 NotificationName

라는 알림을 수신 할 CFNotificationCenterGetDarwinNotifyCenter

#include <CoreFoundation/CFNotificationCenter.h> 

/* This function will be called whatever a notification posted with the specified name */ 
void NotificationCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo){ 

} 

void addObserver(){ 
    CFStringRef name = CFSTR("NotificationName"); 
    CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),&NotificationCallback,name,NULL,CFNotificationSuspensionBehaviorDeliverImmediately); 
} 

를 사용하여 CFNotificationCenter 시도

,
void postNotification(){ 
    CFStringRef name = CFSTR("NotificationName"); 
    /* You have to create the userInfo dictionary and add all the keys to it */ 
    CFDictionaryRef userInfo; 
    CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), name, NULL, userInfo, true); 
} 
관련 문제