これを行う方法はいくつかあります。
すべてのSwiftで、ヘッダーファイルを変更する必要はありません。
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)
出典
2017-10-18 22:42:34
idz
ありがとう@idz ...それは完璧に細かく動作します – Suraj