2

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?

Nate
  • 31,017
  • 13
  • 83
  • 207
Suge
  • 2,808
  • 3
  • 48
  • 79
  • Please tell us more about this. Are you writing a MobileSubstrate *tweak* to run within SpringBoard, and also some normal apps? How often do these apps need to access the data? Many times per second? Who is writing the data, and who is reading the data (SpringBoard, apps, etc.)? – Nate Jul 21 '13 at 05:50
  • Yes, It's a tweak app.In this app, a operation will set the flag, and in another place: `UIResponder` hook, there the flag will be checked frequently, almost 100 times in a seconds.The `UIResponder` hook will influence every app.So in every active app, the flag will be accessed. – Suge Jul 21 '13 at 06:09

2 Answers2

4

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.

creker
  • 9,400
  • 1
  • 30
  • 47
  • +1, but I would actually recommend that he not use a file at all. The value of the variable can be transmitted with the notification. – Nate Jul 21 '13 at 20:53
  • @creker, that sounds very good and I'll try it later.Meanwhile, Is this method high-speed and real-time?Thank you very much. – Suge Jul 25 '13 at 02:04
  • but Bob said the frequency is about 100 times in a seconds. is this really proper for it? –  Jul 26 '13 at 11:15
  • I read about 100 times in a second but I didn't fully understand it's meaning - is it needs to be 100 times in a second or it's a temporary solution of the problem. Question doesn't mention anything about required performance. As for performance of my solution, I suggest you test it yourself to see if it fully suits you. It's isn't real-time because it's not possible in non real-time OS. But delays should be pretty small I guess. Most of the OS components talk to each other this way. – creker Jul 26 '13 at 21:10
  • Updated my answer. It appears distributed center can't be created using my code which is strange because I remeber it was working. Provided another solution - CFMessagePort. – creker Jul 26 '13 at 21:39
  • CFNotificationCenterGetDistributedCenter - I get linker error even after linking with CoreFoundation. iOS 6.1 header says its not for phones? - #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) || TARGET_OS_WIN32 CF_EXPORT CFNotificationCenterRef CFNotificationCenterGetDistributedCenter(void); #endif Any idea how to solve this? – TorukMakto Aug 06 '13 at 03:57
0

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

Andrew
  • 1,088
  • 10
  • 21