/// <summary> /// 开始监听链接 /// </summary> /// <param name="errorCallBack">链接出错回调</param> 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(this.deviceNotificationCallback, 0, 1, 0, ref zero); if (error != kAMDError.kAMDSuccess) { if (ListenErrorEvent != null) { ListenErrorEvent(this, new ListenErrorEventHandlerEventArgs("AMDeviceNotificationSubscribe failed with error : " + error.ToString(), ListenErrorEventType.StartListen)); } } IntPtr userInfo = IntPtr.Zero; error = (kAMDError)MobileDevice.AMRestoreRegisterForDeviceNotifications(this.deviceDFUConnectedNotificationCallback, this.deviceRecoveryConnectedNotificationCallback, this.deviceDFUDisConnectedNotificationCallback, this.deviceRecoveryDisConnectedNotificationCallback, 0, ref userInfo); if (error != kAMDError.kAMDSuccess) { if (ListenErrorEvent != null) { ListenErrorEvent(this, new ListenErrorEventHandlerEventArgs("AMRestoreRegisterForDeviceNotifications failed with error : " + error.ToString(), ListenErrorEventType.StartListen)); } } } catch (Exception ex) { if (ListenErrorEvent != null) { ListenErrorEvent(this, new ListenErrorEventHandlerEventArgs(ex.Message, ListenErrorEventType.StartListen)); } } } }