How to get the FrontMost app - iOS8
I used to use spring framework to get frontmost App, it works fine until ios7 but in iOS8. I am not getting the name of the most recent application. I am using this code.
#define SBSERVPATH "/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices"
#define UIKITPATH "/System/Library/Framework/UIKit.framework/UIKit"
//To get port
mach_port_t *p;
void *uikit = dlopen(UIKITPATH, RTLD_LAZY);
int (*SBSSpringBoardServerPort)() =
dlsym(uikit, "SBSSpringBoardServerPort");
p = (mach_port_t *)SBSSpringBoardServerPort();
dlclose(uikit);
void *sbserv = dlopen(SBSERVPATH, RTLD_LAZY);
void* (*SBFrontmostApplicationDisplayIdentifier)(mach_port_t* port,char * result) =
dlsym(sbserv, "SBFrontmostApplicationDisplayIdentifier");
//Get frontmost application
char frontmostAppS[256];
memset(frontmostAppS,sizeof(frontmostAppS),0);
SBFrontmostApplicationDisplayIdentifier(p,frontmostAppS);
NSString * frontmostApp=[NSString stringWithFormat:@"%s",frontmostAppS];
Can someone please help me figure it out. or anyone where I am wrong can add light. Thanks in advance.
+3
source to share
2 answers
If you are in a Jailbroken environment and connect to SpringBoard, you can use SpringBoard _accessibilityFrontMostApplication
to get a link to the frontmost one SBApplication
:
[[SpringBoard sharedApplication] _accessibilityFrontMostApplication]
If it returns nil
, the user is on the home screen.
0
source to share