I know we can use contextIdAtPosition
and taskPortOfContextId
to get the mach_port_t
of the front top app, but when inside some app, we can not use contextIdAtPosition
to get the context id of SpringBoard
(it's at background), so how can we get the mach_port_t
of SpringBoard
? Thank you!
Asked
Active
Viewed 1,474 times
0

Suge
- 2,808
- 3
- 48
- 79
2 Answers
1
There is a SpringboardService framework.
It has a function SBSSpringBoardServerPort()
which returns Springboard mach port.
Note: Each application may have multiple mach ports, so I am not sure that it's one which you need.

Victor Ronin
- 22,758
- 18
- 92
- 184
-
Thank you for your help, I tried `SBSSpringBoardServerPort()` as you said but got the wrong port, could you take a look at my code above in my post addition?Thank you! – Suge Feb 10 '14 at 02:16
-
You should show a code which where you use the port. As I said, each app may expose multiple ports for different purposes. – Victor Ronin Feb 11 '14 at 15:27
-
I need get the port to make a `IOHIDEventSystemConnectionRef` to the `IOHID` system, it looks like I shall get the `task port` of `SpringBoard`, how can I get the `task port`?Thank you! – Suge Feb 12 '14 at 01:58
-
@ Suge Please did u get a solution? I get a solution to have a programmatically send event on iOS7 simulator but on device no I thought that the problem is the task port... – Dhekra Zaied Nov 17 '14 at 07:58
1
according to http://theiphonewiki.com/wiki//System/Library/LaunchDaemons/com.apple.SpringBoard.plist, the SpringBoard has exposed a lot of services. two of them might (or might not) be of your interests:
- "com.apple.iohideventsystem"
- "com.apple.springboard"
Here is the sample code to query the ports by service names.
#include <mach/mach.h>
#include "bootstrap.h"
#include <stdio.h>
#include <stdlib.h>
#define CHECK_MACH_ERROR(a) do {kern_return_t rr = (a); if ((rr) != KERN_SUCCESS) \
{ printf("Mach error %x (%s) on line %d of file %s\n", (rr), mach_error_string((rr)), __LINE__, __FILE__); abort(); } } while (0)
int main(int argc, char **argv, char **envp)
{
mach_port_t bp = MACH_PORT_NULL;
mach_port_t sp = MACH_PORT_NULL;
kern_return_t err = task_get_bootstrap_port(mach_task_self(), &bp);
CHECK_MACH_ERROR(err);
printf("bp:%d\n", bp);
err = bootstrap_look_up(bp, "com.apple.iohideventsystem", &sp);
CHECK_MACH_ERROR(err);
printf("iohideventsystem:%d\n", sp);
err = bootstrap_look_up(bp, "com.apple.springboard", &sp);
CHECK_MACH_ERROR(err);
printf("springboard:%d\n", sp);
// need to deallocate ports before exit
return 0;
}
The output:
my-iPad:~ root# /usr/bin/port_query
bp:519
iohideventsystem:4099
springboard:4355

Nick X
- 176
- 1
- 7
-
Thank you very much, Nick, but do you know how to get the context id of `SpringBoard`?I need use `taskPortOfContextId` to get that `task port` of `context`. – Suge Mar 01 '14 at 15:47
-
1Maybe I should get the `task port` of `SBApplication`, how can I archive that?Could you take a look at this: http://stackoverflow.com/questions/22243657/how-to-get-task-port-of-sbapplication-in-ios-7-jailbroken, Thank you very much! – Suge Mar 07 '14 at 07:03