Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Getting device list in Swift using libimobiledevice
import Foundation
var i: CInt = 0
var device_list: UnsafeMutablePointer<UnsafeMutablePointer<Int8>> = nil
idevice_get_device_list(&device_list, &i)
print("number of devices: \(i)")
let array = Array(UnsafeBufferPointer(start: device_list, count: Int(i)))
for var device in array {
if let deviceName = String.fromCString(device) {
print("\tdevice: \(deviceName)")
}
}
idevice_device_list_free(device_list)
@kiontupper
Copy link

I know this is old, but how did you get libimobiledevice to link with Swift properly? I have everything installed (ideviceinfo works), but adding libimobiledevice.dylib as a dependency in Xcode doesn't make it available in Swift. I wouldn't normally bother you but I couldn't find anything online.

@robm92
Copy link

robm92 commented May 20, 2022

I know this is old, but how did you get libimobiledevice to link with Swift properly? I have everything installed (ideviceinfo works), but adding libimobiledevice.dylib as a dependency in Xcode doesn't make it available in Swift. I wouldn't normally bother you but I couldn't find anything online.

Try adding the source to the Xcode project then importing the libimobiledevice.h file into the bridging header

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment