在网上搜到的代码都是使用dlopen的方式去加载,但是我编译的时候,一直提示返回值类型不匹配的问题,报错如下:
cannot initialize a variable of type ‘int (*)()’ with an rvalue of type
‘void *’
int (*SBSSpringBoardServerPort)() = dlsym(uikit, “SBSSpringBoardServerPort”);
这是我参照的代码:
void* uikit = dlopen("/System/Library/Framework/UIKit.framework/UIKit", RTLD_LAZY);
int (*SBSSpringBoardServerPort)() = dlsym(uikit, “SBSSpringBoardServerPort”);
mach_port_t *p = (mach_port_t *)SBSSpringBoardServerPort();
dlclose(uikit);
void* sbserv = dlopen("/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices", RTLD_LAZY);
NSArray* (*SBSCopyApplicationDisplayIdentifiers)(mach_port_t* port, BOOL runningApps, BOOL debuggablet) =
dlsym(sbserv, "SBSCopyApplicationDisplayIdentifiers");
NSArray *currentArr = SBSCopyApplicationDisplayIdentifiers(p, YES, YES);
NSLog(@"%@", currentArr);
有大佬做过这种吗,万分感谢