3

Earlier I was using spring board framework to get frontmost App it is working fine upto ios7 , but in iOS8 . I am not getting frontmost App name. 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 any one please help me to work it out. or any where I have mistake , can please add a light. Thanks in advance.

JAL
  • 41,701
  • 23
  • 172
  • 300
Saroj Kumar ojha
  • 485
  • 4
  • 15

3 Answers3

3

You probably can't. According to this post, getting the front most app via SBFrontmostApplicationDisplayIdentifier is considered a privacy leak and has been blocked in iOS 8.

mringwal
  • 476
  • 3
  • 10
0

If you're on a Jailbroken environment and hooking into SpringBoard you can use SpringBoard's _accessibilityFrontMostApplication to get a reference to the frontmost SBApplication:

[[SpringBoard sharedApplication] _accessibilityFrontMostApplication]

If this returns nil the user is on the home screen.

JAL
  • 41,701
  • 23
  • 172
  • 300
0

After doing some reversing of SpringBoard and FrontBoard private frameworks, I managed to get the frontmost app of an iOS 14 (jailbroken) using SBFrontmostApplicationDisplayIdentifier just putting the binary inside a path like /usr/sbin

pitsi
  • 1