应用程序终止后,dlopen返回NULL

时间:2016-02-15 08:27:38

标签: ios dlopen dynamic-library

我使用dlsym加载私有API(在iOS 9.3上需要):

handle = dlopen(CORETELPATH, RTLD_LAZY);
_CTServerConnectionCreate = dlsym(handle, "_CTServerConnectionCreate");

当我杀死应用程序(在多任务模式下从底部滑动)并重新启动应用程序时,它会在第二行崩溃。

handle等于NULL,我没有成功加载lib两次。

我尝试使用dlerror()收到错误,但它也返回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");
            }

1 个答案:

答案 0 :(得分:0)

似乎将私有API路径更改为公共修复问题;并且对私有API的调用仍然有效:

#define CORETELPATH "/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony"