Search code examples
iphoneiosobjective-cjailbreak

How to create a global environment variable that can be accessed by SpringBoard or other applications in the jailbroken iPhone?


I found that a variable created in SpringBoard can not be accessed by other regular applications. But now I want to make a flag variable that can share status in the global environment efficiently.

I thought a file created at some path could do that, but that may be not fast enough.

Does any body know how to do this?


Solution

  • You can try combination of a file with notifications of changes in this file. Notifications between processes can be sent in two ways:

    1. Darwin notification center CFNotificationCenterGetDarwinNotifyCenter
    2. Distributed notification center CFNotificationCenterGetDistributedCenter - private API

    Distributed notification center is better because you can send notification with some data attached to it. Darwin notification center ignores all user info passed to it. So when you changed some flag and saved it in a file you can send notification with this flag's new value. You don't even need to open file and get flag's value yourself. All other apps just need to listen for this notification.

    Here is CFNotificationCenterGetDistributedCenter prototype

    CFNotificationCenterRef CFNotificationCenterGetDistributedCenter();
    

    Update:

    This function is available in iOS 5.0 and above. If you need to support older versions there are two solutions:

    1. Darwin notification center
    2. CFMessagePort - can transmit arbitary data.

    If you really need to support older versions I suggest you using CFMessagePort. It's simple and flexible solution, well documented. If you having troubles with it you can always find working examples.