/// <summary> /// 链接到设备并开启相应服务,无需单独调用,在NotifyCallback已经调用 /// </summary> /// <returns></returns> private unsafe bool ConnectToPhone() { if (MobileDevice.AMDeviceConnect(this.iPhoneHandle) == 1) { throw new Exception("Phone in recovery mode, support not yet implemented"); } if (MobileDevice.AMDeviceIsPaired(this.iPhoneHandle) == 0) { return(false); } if (MobileDevice.AMDeviceValidatePairing(this.iPhoneHandle) != 0) { return(false); } if (MobileDevice.AMDeviceStartSession(this.iPhoneHandle) == 1) { return(false); } //检测是否存在afc2服务 if (MobileDevice.AMDeviceStartService(this.iPhoneHandle, MobileDevice.CFStringMakeConstantString("com.apple.afc2"), ref this.hService, null) != 0) { //打开afc服务 if (MobileDevice.AMDeviceStartService(this.iPhoneHandle, MobileDevice.CFStringMakeConstantString("com.apple.afc"), ref this.hService, null) != 0) { return(false); } } else { this.wasAFC2 = true; } if (MobileDevice.AFCConnectionOpen(this.hService, 0, ref this.hAFC) != 0) { return(false); } this.connected = true; //开启安装IPA服务 if (MobileDevice.AMDeviceStartService(this.iPhoneHandle, MobileDevice.CFStringMakeConstantString("com.apple.mobile.installation_proxy"), ref this.installFD, null) != 0) { return(false); } return(true); }
/// <summary> /// 上传IPA程序到/var/mobile/Media/PublicStaging /// 如果已经越狱,则会传到/PublicStaging,无法被InstallApplication调用,建议对于已经越狱的设备通过AFC操作手动上传IPA /// </summary> /// <param name="path">PC端IPA文件地址</param> public unsafe bool TransferApplication(string path) { int i = MobileDevice.AMDeviceTransferApplication(this.hService, MobileDevice.CFStringMakeConstantString(path), null, installCallBack, null); return(i == (int)kAMDError.kAMDSuccess); }
/// <summary> /// 卸载IPA功能函数 /// </summary> /// <param name="bundleIdentifier">APP的BundleIdentifier,例如com.tongbu.tui</param> /// <returns>是否成功卸载</returns> public unsafe bool UnInstallApplication(string bundleIdentifier) { int i = MobileDevice.AMDeviceUninstallApplication(this.installFD, MobileDevice.CFStringMakeConstantString(bundleIdentifier), IntPtr.Zero, null, null); return(i == (int)kAMDError.kAMDSuccess); }
/// <summary> /// 安装IPA程序,支持回调跟踪进度(暂未实现) /// </summary> /// <param name="path">PC端IPA文件地址</param> public unsafe bool InstallApplication(string path) { int i = MobileDevice.AMDeviceInstallApplication(this.installFD, MobileDevice.CFStringMakeConstantString(path), null, null, null); return(i == (int)kAMDError.kAMDSuccess); }