/// <summary> /// 开始监听链接 /// 需要使用线程方式调用 /// </summary> public void StartListen() { if (!iSStartListen) { iSStartListen = true; try { deviceNotificationCallback = NotificationCallback; deviceDFUConnectedNotificationCallback = DfuConnectCallback; deviceRecoveryConnectedNotificationCallback = RecoveryConnectCallback; deviceDFUDisConnectedNotificationCallback = DfuDisconnectCallback; deviceRecoveryDisConnectedNotificationCallback = RecoveryDisconnectCallback; IntPtr zero = IntPtr.Zero; kAMDError error = (kAMDError)MobileDevice.AMDeviceNotificationSubscribe(deviceNotificationCallback, 0, 1, 0, ref zero); if (error != kAMDError.kAMDSuccess) { //Check "Apple Mobile Device Service" status ListenErrorEvent?.Invoke(this, new ListenErrorEventHandlerEventArgs("AMDeviceNotificationSubscribe failed with error : " + error, ListenErrorEventType.StartListen)); } IntPtr userInfo = IntPtr.Zero; error = (kAMDError)MobileDevice.AMRestoreRegisterForDeviceNotifications(deviceDFUConnectedNotificationCallback, deviceRecoveryConnectedNotificationCallback, deviceDFUDisConnectedNotificationCallback, deviceRecoveryDisConnectedNotificationCallback, 0, ref userInfo); if (error != kAMDError.kAMDSuccess) { ListenErrorEvent?.Invoke(this, new ListenErrorEventHandlerEventArgs("AMRestoreRegisterForDeviceNotifications failed with error : " + error, ListenErrorEventType.StartListen)); } //LoopRun CoreFoundation.CFRunLoopRun(); } catch (Exception ex) { if (ListenErrorEvent != null) { ListenErrorEvent(this, new ListenErrorEventHandlerEventArgs(ex.Message, ListenErrorEventType.StartListen)); } } } }