libimobiledevice-win32 / imobiledevice-net

.NET (C#, VB.NET,...) bindings for libimobiledevice
GNU Lesser General Public License v2.1
299 stars 77 forks source link

Little help with an example #134

Open AjayGhale opened 4 years ago

AjayGhale commented 4 years ago

im trying to make a GUI just to show the connected device info, and i dont even know how to start.. i once make a program but only iOS 9 devices are detected newer devices are not detected can someone give me a hand?? for example, i want to display device name, iOS version, UDID on labels in the windows form, im using visual studio 2019 C# thanks in advance...

devlucy commented 4 years ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using iMobileDevice;
using iMobileDevice.iDevice;
using iMobileDevice.Lockdown;

namespace iMobileDevices
{
public class GetDeviceInfo
{
ILockdownApi lockdown = LibiMobileDevice.Instance.Lockdown;

    public  GetDeviceInfo() {
        NativeLibraries.Load(); // needs to call to load NativeLibraries
        int count = 0;
        LibiMobileDevice.Instance.iDevice.idevice_get_device_list(out var udids, ref count); // gives you list of
        iDeviceHandle iDeviceHandle;
        LockdownClientHandle lockdownClientHandle;
        iDevice.idevice_new(out iDeviceHandle, udids[0]); // see here I am checking with device found at 0th index,you can iterate over list of udids
        lockdown.lockdownd_client_new_with_handshake(iDeviceHandle, out lockdownClientHandle, "Label").ThrowOnError("Unable to read device");
        lockdown.lockdownd_get_device_name(lockdownClientHandle, out var deviceName).ThrowOnError("Failed to get device name."); // deviceName will give you deviceName
        lockdown.lockdownd_client_new_with_handshake(iDeviceHandle, out lockdownClientHandle, "handshake").ThrowOnError("Cannot read device");
        lockdown.lockdownd_get_value(lockdownClientHandle, null, "ProductVersion", out var node).ThrowOnError("Failed to get device system version.");
        LibiMobileDevice.Instance.Plist.plist_get_string_val(node, out var version); // version will give you device version
        ideviceHandle.Dispose();
        lockdownClientHandle.Dispose();
    }
}
AjayGhale commented 4 years ago

oh thanks really thanks for this... i dont know if i forgot everything about programming but i want that the name of device and iOS version gets showed on a label in a windows form.. sorry for my inglish and thans in advance again!