首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >修改SCDynamicStore.h的标头

修改SCDynamicStore.h的标头
EN

Stack Overflow用户
提问于 2017-10-18 14:17:10
回答 1查看 429关注 0票数 1

我正在试图检测iOS中的热点状态。为此,我需要使用SystemConfiguration API如下所示

代码语言:javascript
运行
复制
let sc = SCDynamicStoreCreate(nil, "com.apple.wirelessmodemsettings.MISManager" as CFString, nil, nil)
let info = SCDynamicStoreCopyValue(sc, "com.apple.MobileInternetSharing" as CFString)

但是SCDynamicStoreCreateSCDynamicStoreCopyValue并不适用于iOS。我需要修改SCDynamicStore.h文件,并使这些函数可用于iOS (它们目前仅对Mac可用)。

此链接提到了通过创建重复的头来实现此操作的一种方法。SCDynamicStoreCreate is unavailable: not available on iOS。但这种方法对我来说不是很快的。

如何才能迅速做到这一点?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-10-18 22:42:34

有几种方法你可以做到。

这里有一种方法是Swift,不涉及更改头文件。

代码语言:javascript
运行
复制
    import SystemConfiguration

    // Define types for each of the calls of interest
    typealias TSCDynamicStoreCreate = @convention (c) (_ allocator: CFAllocator?, _ name: CFString, _ callout: SystemConfiguration.SCDynamicStoreCallBack?, _ context: UnsafeMutablePointer<SCDynamicStoreContext>?) -> SCDynamicStore?
    typealias TSCDynamicStoreCopyValue = @convention (c) (_ store: SCDynamicStore?, _ key: CFString) -> CoreFoundation.CFPropertyList?

    // Get a handle to the library, the flag `RT_NOLOAD` will limit this
    // to already loaded libraries
    let hLibrary = dlopen("/System/Library/Frameworks/SystemConfiguration.framework/SystemConfiguration", RTLD_NOLOAD);

    // Load addresses of the functions from the library
    let MySCDynamicStoreCreate = unsafeBitCast(dlsym(hLibrary, "SCDynamicStoreCreate"), to: TSCDynamicStoreCreate.self)
    let MySCDynamicStoreCopyValue = unsafeBitCast(dlsym(hLibrary, "SCDynamicStoreCopyValue"), to: TSCDynamicStoreCopyValue.self)

    // Setup constants
    let name = "com.apple.wirelessmodemsettings.MISManager" as CFString
    let key = "com.apple.MobileInternetSharing" as CFString

    // Call the functions through the looked up addresses
    let dynamicStore = MySCDynamicStoreCreate(nil, name, nil, nil)
    let plist = MySCDynamicStoreCopyValue(dynamicStore, key)
    dump(plist)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46812375

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档