[英]Get attached device serial number in C#
I am trying to get data from attached devices through C#. 我正在尝试通过C#从连接的设备获取数据。 Specifically I need to get the serial number from iOS devices. 具体来说,我需要从iOS设备获取序列号。
I see the data is available to me from the attached photo, but I am looking for a way to get this information in C#. 我从所附的照片中可以看到数据,但是我正在寻找一种使用C#获取此信息的方法。
Does anyone know how to access this information in C#? 有谁知道如何在C#中访问此信息?
imobiledevice-net provides a C# API you can use to interact with iOS devices attached to a Windows, Linux or macOS machine. imobiledevice-net提供了C#API,可用于与连接到Windows,Linux或macOS计算机的iOS设备进行交互。
There's sample code in the README which helps you list the UDIDs of all devices connected to your PC: 自述文件中包含示例代码,可帮助您列出连接到PC的所有设备的UDID:
ReadOnlyCollection<string> udids;
int count = 0;
var idevice = LibiMobileDevice.Instance.iDevice;
var lockdown = LibiMobileDevice.Instance.Lockdown;
var ret = idevice.idevice_get_device_list(out udids, ref count);
if (ret == iDeviceError.NoDevice)
{
// Not actually an error in our case
return;
}
ret.ThrowOnError();
// Get the device name
foreach (var udid in udids)
{
Console.WriteLine(udid);
}
Let me know if this helps! 让我知道这是否有帮助!
Placing the code below after lockdown.lockdownd_client_new_with_handshake(deviceHandle, out lockdownHandle, "Quamotion").ThrowOnError();
在lockdown.lockdownd_client_new_with_handshake(deviceHandle, out lockdownHandle, "Quamotion").ThrowOnError();
之后放置以下代码lockdown.lockdownd_client_new_with_handshake(deviceHandle, out lockdownHandle, "Quamotion").ThrowOnError();
you will be able to access values like the serial number or iOS version. 您将能够访问序列号或iOS版本等值。 This is only a crude example: 这只是一个粗略的例子:
string t1;
string t2;
PlistHandle tested1;
PlistHandle tested2;
//Find serial number in plist
lockdown.lockdownd_get_value(lockdownHandle, null, "SerialNumber", out
tested1);
//Find IOS version in plist
lockdown.lockdownd_get_value(lockdownHandle, null, "ProductVersion", out
tested2);
//Get string values from plist
tested1.Api.Plist.plist_get_string_val(tested1, out t1);
tested2.Api.Plist.plist_get_string_val(tested2, out t2);
//Place data in textboxes
serialTXT.Text = t1.Trim();
verTXT.Text = t2.Trim();
You will need to have NativeLibraries.Load();
您将需要具有NativeLibraries.Load();
in your code first and pull in any necessary iMobileDevice using references. 首先在您的代码中,然后使用引用引入任何必要的iMobileDevice。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.