/// <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));
             }
         }
     }
 }
Esempio n. 2
0
        /// <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));
                    }
                }
            }
        }
 public static extern int AMRestoreRegisterForDeviceNotifications(
     DeviceDFUNotificationCallback dfu_connect, DeviceRestoreNotificationCallback recovery_connect,
     DeviceDFUNotificationCallback dfu_disconnect, DeviceRestoreNotificationCallback recovery_disconnect,
     uint unknown0, ref IntPtr user_info);
 public static extern int AMRestoreRegisterForDeviceNotifications(
     DeviceDFUNotificationCallback dfu_connect, DeviceRestoreNotificationCallback recovery_connect,
     DeviceDFUNotificationCallback dfu_disconnect, DeviceRestoreNotificationCallback recovery_disconnect,
     uint unknown0, ref IntPtr user_info);