我想在iOS平台上使用'dlopen()'函数调用动态库,'dlopen()'函数是私有API吗?
我想在iOS平台上使用'dlopen()'函数调用动态库,'dlopen()'函数是私有API吗?
#import <dlfcn.h>
void printApplicationState()
{
Class UIApplicationClass = NSClassFromString(@"UIApplication");
if (Nil == UIApplicationClass) {
void *handle = dlopen("System/Library/Frameworks/UIKit.framework/UIKit", RTLD_NOW);
if (handle) {
UIApplicationClass = NSClassFromString(@"UIApplication");
assert(UIApplicationClass != Nil);
NSInteger applicationState = [UIApplicationClass applicationState];
printf("app state: %ti\n", applicationState);
if (0 != dlclose(handle)) {
printf("dlclose failed! %s\n", dlerror());
}
} else {
printf("dlopen failed! %s\n", dlerror());
}
} else {
printf("app state: %ti\n", [UIApplicationClass applicationState]);
}
}
void* handle = dlopen("/System/Library/Frameworks/UIKit.framework/UIKit", RTLD_NOW);
然后您可以通过调用 dlclose(handle);
卸载它(将加载计数减少1)。请务必阅读文档以获取更多信息。https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/dlopen.3.html - NSProgrammer