我使用首选项包控制器类保存了一些数据。我想与它的 tweak文件分享它,即我希望跳板能够传递首选项包以便从中获取一些数据,反之亦然。我试图使用Libobjcipc - 正如其文档中所述:
libobjcipc是一个开发人员库,为越狱iOS提供进程间通信(在app和SpringBoard之间)。它处理SpringBoard和app进程之间的套接字连接......
我曾尝试从tweak发送消息,但无法弄清楚如何在我的首选项捆绑控制器中接收传入消息。我知道方法[OBJCIPC registerIncomingMessageFromSpringBoardHandlerForMessageName:handler:]
将用于此目的。但是我在哪里使用它?希望得到一些积极的回应...谢谢..
修改
我在@creker建议后尝试使用CFNotificationCenter
。我可以发送通知,但我的调整无法接收,因此不会执行回调方法callBackNotification
。这是更改的代码:
Tweak.xm
//at the end of tweak file
static void callBackNotification(CFNotificationCenterRef center,void *observer,CFStringRef name,const void *object,CFDictionaryRef userInfo)
{
NSLog(@"Notification received!");
}
%ctor
{
NSLog(@"Init cqlled!"); //this piece of code called successfully
//Register for the change notification
CFNotificationCenterRef r = CFNotificationCenterGetDarwinNotifyCenter();
CFNotificationCenterAddObserver(r, NULL, reloadPrefsNotification, CFSTR("ccom.identifier.message"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
}
偏好捆绑控制器
@interface SettingsListController: PSListController {
}
@end
@implementation SettingsListController
- (id)specifiers {
if(_specifiers == nil) {
_specifiers = [[self loadSpecifiersFromPlistName:@"JRLockerSettings" target:self] retain];
}
return _specifiers;
}
-(void) postNotification()
{
CFNotificationCenterRef center = CFNotificationCenterGetLocalCenter();
// post a notification
CFDictionaryKeyCallBacks keyCallbacks = {0, NULL, NULL, CFCopyDescription, CFEqual, NULL};
CFDictionaryValueCallBacks valueCallbacks = {0, NULL, NULL, CFCopyDescription, CFEqual};
CFMutableDictionaryRef dictionary = CFDictionaryCreateMutable(kCFAllocatorDefault, 1,
&keyCallbacks, &valueCallbacks);
CFDictionaryAddValue(dictionary, CFSTR("identifier"), CFSTR("value"));
CFNotificationCenterPostNotification(center, CFSTR("com.identifier.message"), NULL, dictionary, TRUE);
CFRelease(dictionary);
}
@end