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