dlopen returns 应用终止后为 NULL
dlopen returns NULL after app kill
我正在使用 dlsym
加载私有 API(iOS 9.3 需要):
handle = dlopen(CORETELPATH, RTLD_LAZY);
_CTServerConnectionCreate = dlsym(handle, "_CTServerConnectionCreate");
当我终止应用程序(在多任务模式下从底部滑动)并重新启动应用程序时,它在第二行崩溃。
handle
等于NULL
我两次加载库都没有成功
我试图用 dlerror()
得到错误,但它 returns 也 NULL
。
有人遇到这个问题吗?如何解决?
编辑:
这是完整的代码; if (handle != NULL)
应用程序不会崩溃,但私有框架也不会加载
#define CORETELPATH "/System/Library/PrivateFrameworks/CoreTelephony.framework/CoreTelephony"
handle = dlopen(CORETELPATH, RTLD_LAZY);
NSLog(@"DL Error : %s", dlerror());
if (handle != NULL) {
_CTServerConnectionCreate = dlsym(handle, "_CTServerConnectionCreate");
CTResultConnection = _CTServerConnectionCreate(NULL, simMonitorCallback, NULL);
_CTServerConnectionAddToRunLoop = dlsym(handle, "_CTServerConnectionAddToRunLoop");
_CTServerConnectionAddToRunLoop(CTResultConnection, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
_CTServerConnectionRegisterForNotification = dlsym(handle, "_CTServerConnectionRegisterForNotification");
_CTServerConnectionUnregisterForNotification = dlsym(handle, "_CTServerConnectionUnregisterForNotification");
_CTServerConnectionRegisterForNotification(CTResultConnection, kCTSIMSupportSIMStatusChangeNotification);
_CTServerConnectionGetSIMStatus = dlsym(handle, "_CTServerConnectionGetSIMStatus");
_CTServerConnectionCopyMobileEquipmentInfo = dlsym(handle, "_CTServerConnectionCopyMobileEquipmentInfo");
}
似乎将 Private API 路径更改为 public 可以解决问题;并且对 private APIs 的调用仍然有效:
#define CORETELPATH "/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony"
我正在使用 dlsym
加载私有 API(iOS 9.3 需要):
handle = dlopen(CORETELPATH, RTLD_LAZY);
_CTServerConnectionCreate = dlsym(handle, "_CTServerConnectionCreate");
当我终止应用程序(在多任务模式下从底部滑动)并重新启动应用程序时,它在第二行崩溃。
handle
等于NULL
我两次加载库都没有成功
我试图用 dlerror()
得到错误,但它 returns 也 NULL
。
有人遇到这个问题吗?如何解决?
编辑:
这是完整的代码; if (handle != NULL)
应用程序不会崩溃,但私有框架也不会加载
#define CORETELPATH "/System/Library/PrivateFrameworks/CoreTelephony.framework/CoreTelephony"
handle = dlopen(CORETELPATH, RTLD_LAZY);
NSLog(@"DL Error : %s", dlerror());
if (handle != NULL) {
_CTServerConnectionCreate = dlsym(handle, "_CTServerConnectionCreate");
CTResultConnection = _CTServerConnectionCreate(NULL, simMonitorCallback, NULL);
_CTServerConnectionAddToRunLoop = dlsym(handle, "_CTServerConnectionAddToRunLoop");
_CTServerConnectionAddToRunLoop(CTResultConnection, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
_CTServerConnectionRegisterForNotification = dlsym(handle, "_CTServerConnectionRegisterForNotification");
_CTServerConnectionUnregisterForNotification = dlsym(handle, "_CTServerConnectionUnregisterForNotification");
_CTServerConnectionRegisterForNotification(CTResultConnection, kCTSIMSupportSIMStatusChangeNotification);
_CTServerConnectionGetSIMStatus = dlsym(handle, "_CTServerConnectionGetSIMStatus");
_CTServerConnectionCopyMobileEquipmentInfo = dlsym(handle, "_CTServerConnectionCopyMobileEquipmentInfo");
}
似乎将 Private API 路径更改为 public 可以解决问题;并且对 private APIs 的调用仍然有效:
#define CORETELPATH "/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony"