@wangxiaoning wrote:
已在论坛查到的方式有如下4种,
socket,包括原生socket和websocket
xpc,iOS下不会使用
通知
本地文件存贮
- 其中通知可以发送和接收,但经过反复测试不能携带参数
//App 发送 CFDictionaryRef cfdic = (__bridge CFDictionaryRef)dict; NSLog(@"%@", cfdic); const void *tkeys[1] = { @"testKey" }; const void *tvalues[1] = { @"testValue" }; CFDictionaryRef userInfo = CFDictionaryCreate(NULL, tkeys, tvalues, 1, NULL, NULL); CFNotificationCenterPostNotificationWithOptions(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("OpenAPP"), NULL, userInfo, kCFNotificationPostToAllSessions); // tweak 注册 CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, &OpenAPPNotificationReceivedCallback, CFSTR("OpenAPP"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately); // tweak收到通知的回调 //打开某个程序 static void OpenAPPNotificationReceivedCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) { #error 这里始终收不到 userInfo NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:OpenAppBundleID_Path]; NSString *bundleID = dict[@"bundleID"]; openApp(bundleID); }
- 所以想通过通知配合本地文件存贮内容,tweak收到通知后去本地文件查询这个通知携带的内容
/var/mobile/Library/Preferences
本地存贮的文件都会放在这里路径下,但是总是存贮失败- 这是存储方式
[dict writeToFile:"/var/mobile/Library/Preferences/文件名" atomically:YES];
- 所以想问下各位大佬,Tweak和App如何通信
Posts: 6
Participants: 2