몇 가지 방법이 있습니다.
여기에는 모두 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