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

本小妞迷上赌 提交于 2019-12-02 04:28:55

问题


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?


回答1:


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.




回答2:


You can store your var in the keyChain, and make all app which wanna share it in one access group. Hope it help.



来源:https://stackoverflow.com/questions/17768901/how-to-create-a-global-environment-variable-that-can-be-accessed-by-springboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!