获取当前前台运行的应用程序(第三方)的Bundle标识符

15

如何获取正在前台运行的应用程序名称?在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,不知道是否有人知道它能否帮助解决这个问题?


1
我有同样的问题,但是我还没有找到解决办法。 - Birju
2
可能自 iOS 8 起,苹果已将其禁用。 - Anand
1
看起来FrontBoard是一个私有框架。这对于应用商店的应用程序是行不通的。你可以将其用于自己使用的应用程序或越狱应用程序,但如果你尝试使用这样的私有框架,你将会被应用商店拒绝。 - Duncan C
4
iOS 8中如何确定前台应用程序,以及获取正在运行的应用程序列表,请参见https://dev59.com/jF8e5IYBdhLWcg3wCWx2。但这被认为是一种漏洞,并在iOS 8中被禁用了。 - Michael Latta
希望有一种解决方案适用于iOS8和iOS9。 - tounaobun
1个回答

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接