代码之家  ›  专栏  ›  技术社区  ›  SlumTheSlug

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

  •  2
  • SlumTheSlug  · 技术社区  · 9 年前

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

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

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

    这个 handle 等于 NULL 我没有成功加载两次库。

    我试图用 dlerror() ,但它也会返回 无效的 .

    有人知道这个问题吗?如何解决?

    编辑: 这是完整的代码;使用 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 回复  |  直到 9 年前
        1
  •  0
  •   SlumTheSlug    9 年前

    看来,将私有API路径更改为公共API路径可以解决问题;并且对私有API的调用仍然有效:

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