/// <summary> /// 开启Socket服务 /// </summary> /// <param name="serviceName">服务名</param> /// <param name="serviceSocket">Socket链接</param> /// <returns></returns> private bool StartSocketService(string serviceName, ref int serviceSocket) { var kAMDSuccess = kAMDError.kAMDSuccess; if (serviceSocket > 0)//已经开启服务 { return(true); } if (!this.isConnected) { if (Connect() != (int)kAMDError.kAMDSuccess) { Console.WriteLine("StartService()执行Connect()失败"); return(false); } } bool openSession = false; if (!this.isSessionOpen) { kAMDSuccess = StartSession(); if (kAMDSuccess == kAMDError.kAMDSuccess) { openSession = true; } else { return(false); } } var result = false; var zero = IntPtr.Zero; if ((MobileDevice.AMDeviceSecureStartService(this.DevicePtr, CoreFoundation.StringToCFString(serviceName), IntPtr.Zero, ref zero) == (int)kAMDError.kAMDSuccess)) { serviceSocket = MobileDevice.AMDServiceConnectionGetSocket(zero); result = true; } else if (MobileDevice.AMDeviceStartService(this.DevicePtr, CoreFoundation.StringToCFString(serviceName), ref serviceSocket, IntPtr.Zero) == (int)kAMDError.kAMDSuccess) { result = true; } if (openSession) { StopSession(); } return(result); }