如何获取前台运行的应用名称?它在 iOS 7 中使用 SpringBoard 工作,但在 iOS 8 中我没有得到结果。任何帮助表示赞赏。我不需要在苹果商店提交我的应用程序,所以如果有任何补丁或脚本也可用,请告诉我。
代码在 iOS 8.0 以下运行良好
- (NSMutableString*) getActiveApps
{
mach_port_t *port;
void *lib = dlopen(SBSERVPATH, RTLD_LAZY);
int (*SBSSpringBoardServerPort)() =
dlsym(lib, "SBSSpringBoardServerPort");
port = (mach_port_t *)SBSSpringBoardServerPort();
dlclose(lib);
//mach_port_t * port = [self getSpringBoardPort];
// open springboard lib
//void *lib = dlopen(SBSERVPATH, RTLD_LAZY);
// retrieve function SBFrontmostApplicationDisplayIdentifier
void *(*SBFrontmostApplicationDisplayIdentifier)(mach_port_t *port, char *result) =
dlsym(lib, "SBFrontmostApplicationDisplayIdentifier");
// reserve memory for name
char appId[256];
memset(appId, 0, sizeof(appId));
// retrieve front app name
SBFrontmostApplicationDisplayIdentifier(port, appId);
// close dynlib
dlclose(lib);
return [[NSString stringWithFormat:@"%s", appId] retain];
}
我还展示了新框架 FrontBoard任何人都知道它应该有助于解决这个问题吗?
最佳答案
自从发现一个漏洞后,iOS 8 中就再也没有办法这样做了。后台应用程序可以通过最前面的应用程序进行攻击。更多详情:http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2014-4361
关于ios - 获取当前前台运行的应用程序(第三方)包标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26190725/