0

I have some data saved with preference bundle controller class. I want to share it with its tweak file i.e. I want springboard to be able to communicate preference bundle in order to get some data from it and vice versa. I have tried to use Libobjcipc - as written in its documentation:

libobjcipc is a developer library that provides an inter-process communication (between app and SpringBoard) solution for jailbroken iOS. It handles the socket connections between SpringBoard and app processes...

I have tried to send message from tweak, but unable to figure it out how to receive incoming message in my preference bundle controller. I know the method [OBJCIPC registerIncomingMessageFromSpringBoardHandlerForMessageName:handler:] will be used for this purpose. But where do I use it? Hope for some positive response... Thanks..

EDIT:

I have tried using CFNotificationCenter after suggestion of @creker. I can send notification, but my tweak cannot receive it, and so callback method callBackNotification isn't executed. Here is changed code:

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);
}

Preference Bundle Controller

@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
NightFury
  • 13,436
  • 6
  • 71
  • 120
  • Did you look at this https://github.com/a1anyip/Google-Authenticator-for-ProWidgets/tree/master/AuthenticatorSubstrate ? – creker Jun 14 '14 at 15:44
  • @creker yes I did see that. But that code is for mobilesubstrate.. I want to know how to receive and send message from preference bundle? What's the method name - like in iOS apps, we write such code in `viewDidLoad`. How can I use this https://github.com/a1anyip/Google-Authenticator-for-ProWidgets/blob/master/AuthenticatorSubstrate/AuthenticatorSubstrate.m ? – NightFury Jun 14 '14 at 17:01
  • `viewDidLoad` is a good place for that. Any place in your preferences bundle that will be called upon it's initialization is a good for that. You do understand that you will only be able to communicate while preferences app is in the foreground? – creker Jun 14 '14 at 17:07
  • @creker That's bad... I didn't know that :( so can there be any other solution? – NightFury Jun 14 '14 at 21:29
  • @creker Actually there is a list of apps `(PSSpecifers)` I load dynamically after one taps a `PSLinkCell` in preference screen. Each item (for list of apps) is a `PSSwitchCell` and I need to maintain state of each switch for individual app, so that springboard can use it later on. Did you got my idea? – NightFury Jun 14 '14 at 21:35
  • Here's what you could do. Create some plist in `/var/mobile/Library/Preferences/` directory. Both SpringBoard and Preferences app should have write permissions in it. This plist will store shared data between the two. Now, when you open Preferences app and change some settings using your preferences bundle it will save the changes in the plist and send notification to the SpringBoard. Notification could be either like "the plist changed, reload it" without attaching any data or you could actually send the changes like "the plist changed, here is what has been changed". – creker Jun 14 '14 at 22:20
  • Former can be implemented using Darwin notifications https://developer.apple.com/library/mac/documentation/Darwin/Conceptual/MacOSXNotifcationOv/DarwinNotificationConcepts/DarwinNotificationConcepts.html – creker Jun 14 '14 at 22:22
  • @creker thanks alot for clearing things out. I will try it out on monday at office. Before that please give me hint on two things: 1) how to give write perm? I think I have to do in make file - some chmod command? 2) how springboard will receive notification? What should I hook? Thanks once again! – NightFury Jun 14 '14 at 23:19
  • 1)Yeah, my comment is a bit confusing there. I meant - I don't know for sure but it seems that they have write permissions in that directory. You don't have to set anything. If you look in there you can find `com.apple.preferences.plist` and `com.apple.springboard.plist` files suggesting that they can write in that directory. 2) Everything is in the link. You don't need to hook anything. – creker Jun 15 '14 at 00:08
  • @creker Alright I will see that. Thanks. – NightFury Jun 15 '14 at 09:02
  • @creker I tried what you suggested, but there is a little problem. Can you have a look at my edited post..? Thanks. – NightFury Jun 16 '14 at 18:44
  • 1. You have a typo `ccom.identifier.message`. 2. Darwin center doesn't support `userInfo` argument - it can only send notifications without any data attached to it. 3. `CFNotificationCenterGetDarwinNotifyCenter` should be used for both observing and posting. `CFNotificationCenterGetLocalCenter` is a completely different thing. – creker Jun 16 '14 at 18:56
  • That's why I suggested using a file inside `/var/mobile/Library/Preferences`. Darwin center doesn't support `userInfo` so it can only send notifications saying something like "reload the data". All the data will be in the file. When the file is changed you send notification to tell other process that it needs to reload it's contents. – creker Jun 16 '14 at 19:00
  • Ok. so that means file is the only option I am left with. – NightFury Jun 16 '14 at 19:23
  • If Libobjcipc doesn't work then yes. You could also try this https://developer.apple.com/library/mac/documentation/corefoundation/Reference/CFMessagePortRef/Reference/reference.html It's not as simple as darwin notifications but it can send messages with data attached to them. I use it in my projects and it works very well. Only problem - Preferences app may have a strict sandbox profile which restricts mach ports usage (CFMessagePort is built upon them). For example, Camera app has that kind of restrictions so I use darwin+files in it instead. – creker Jun 16 '14 at 19:35
  • Ah @creker thanks for the ideas man :) I really don't have much time left for implementation. I will probably go with libobjcipc or file usage tomorrow hopefully. I will inform u with results soon :) – NightFury Jun 16 '14 at 19:48

0 Answers0