/// <summary>constructor</summary> /// <param name="targetLog">log engine to use</param> /// <param name="device">type of ios device</param> public iOSClient(LogEngine targetLog, iOSDevice device) : base(targetLog) { // set up action library _BatchCommandQueue_ = new List<string>(); _IsBatchingCommands_ = false; _CommandIndex = -1; _CompiledAppPath = ""; _StartAutomation(device); }
private void CommonConnectDevice(object sender, DeviceCommonConnectEventArgs args) { if (args.Message == MobileDevice.Enumerates.ConnectNotificationMessage.Connected) { currentiOSDevice = args.Device; Console.WriteLine("Device is connected"); //MobileDevice.AMDeviceLookupApplications(); } if (args.Message == MobileDevice.Enumerates.ConnectNotificationMessage.Disconnected) { Console.WriteLine("Device has broken link"); } }
public bool HasTopNotch() { if (null == _device) { _device = new iOSDevice(); } if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0)) { UIEdgeInsets sArea = UIApplication.SharedApplication.Delegate.GetWindow().SafeAreaInsets; Debug.WriteLine("Safe areas: {0}", sArea.ToString()); } return(_device.deviceHasNotch()); }
private void CommonConnectDevice(object sender, DeviceCommonConnectEventArgs args) { if (args.Message == MobileDevice.Enumerates.ConnectNotificationMessage.Connected) { currentiOSDevice = args.Device; SetData(true); if (headless == true) { DoActivate(); } } if (args.Message == MobileDevice.Enumerates.ConnectNotificationMessage.Disconnected) { SetData(false); } }
private void CommonConnectDevice(object sender, DeviceCommonConnectEventArgs args) { if (args.Message == MobileDevice.Enumerates.ConnectNotificationMessage.Connected) { currentiOSDevice = args.Device; this.Invoke(new Action(() => { StateLabel.Text = "Device is connected"; })); } if (args.Message == MobileDevice.Enumerates.ConnectNotificationMessage.Disconnected) { this.Invoke(new Action(() => { StateLabel.Text = "Device has broken link"; })); } }
private void CommonConnectDevice(object sender, DeviceCommonConnectEventArgs args) { if (args.Message == ConnectNotificationMessage.Connected) { currentiOSDevice = args.Device; this.Invoke(new Action(() => { StateLabel.Text = "设备已连接"; })); } if (args.Message == ConnectNotificationMessage.Disconnected) { this.Invoke(new Action(() => { StateLabel.Text = "设备已断开链接"; })); } }
internal DeviceCommonConnectEventArgs(iOSDevice device, ConnectNotificationMessage message) { this.device = device; this.message = message; }
/// <summary>launches the app in the iphone simulator</summary> /// <param name="device">type of ios device</param> /// <returns>true if successful</returns> private bool _StartAutomation(iOSDevice device) { if (IsAutomationRunning()) return true; // create a new directory for the automation _iOSAutomationDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Directory.CreateDirectory(_iOSAutomationDirectory); // write bootstrap.js and file writer string bootstrapPath = Path.Combine(_iOSAutomationDirectory, "bootstrap.js"); string instrumentsTemplatePath = Path.Combine(_iOSAutomationDirectory, "Automation.tracetemplate"); File.Copy(Path.Combine(Directory.GetCurrentDirectory(), "Automation.tracetemplate"), instrumentsTemplatePath); StreamWriter sw = new StreamWriter(bootstrapPath); sw.Write(Automation.Properties.Resources.bootstrap.Replace("$PATH_ROOT", _iOSAutomationDirectory + "/")); sw.Close(); sw = new StreamWriter(Path.Combine(_iOSAutomationDirectory, "writeResponse.py")); sw.Write(Automation.Properties.Resources.writeResponse); sw.Close(); // clean the simulator Utility.SystemOperations.CleaniOSSimulator(); // delete old builds string buildDir = Path.Combine(System.Environment.GetEnvironmentVariable("HOME"), "Library/Application Support/iPhone Simulator"); if (Directory.Exists(buildDir)) foreach (string subdir in Directory.GetDirectories(buildDir)) Utility.SystemOperations.DeleteDirectory(new DirectoryInfo(Path.Combine(buildDir, subdir))); // find the xcode project if it was not supplied in settings CommandResult cr; if (Settings.iOS.XCodeProjectPath == "") { cr = Utility.SystemOperations.RunShellCommand("/usr/bin/mdfind", "-name \"" + _XCodeProjName + "\""); if (!cr.WasSuccessful) Log.CriticalError("Could not find the .xcodeproj file:" + cr.CommandOutput); Settings.iOS.XCodeProjectPath = cr.CommandOutput.Split(new char[] { '\n' })[0]; } // point the xcode project at the supplied dev instance string xcodeProjDirectory = Path.GetDirectoryName(Settings.iOS.XCodeProjectPath); // compile the xcode project string oldDirectory = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(xcodeProjDirectory); ProcessStartInfo xCodeBuildProcInfo = new ProcessStartInfo(); xCodeBuildProcInfo.FileName = "/usr/bin/xcodebuild"; xCodeBuildProcInfo.Arguments = _XCodeBuildArgs + " TARGETED_DEVICE_FAMILY=" + ((int)device).ToString(); xCodeBuildProcInfo.UseShellExecute = true; Process xCodeBuildProc = Process.Start(xCodeBuildProcInfo); xCodeBuildProc.WaitForExit(); Directory.SetCurrentDirectory(oldDirectory); // find the compiled app using spotlight since you cannot read stdout when using shell execute int numberOfAttemptsToFindTheCompiledApp = 0; while (_CompiledAppPath == "" && numberOfAttemptsToFindTheCompiledApp < 15) { cr = Utility.SystemOperations.RunShellCommand("/usr/bin/mdfind", "-name \"" + _iOSAppName + "\""); if (!cr.WasSuccessful) Log.CriticalError("Could not find the .app file:" + cr.CommandOutput); foreach (string projPath in cr.CommandOutput.Split(new char[] { '\n' })) { if (projPath.Contains("DerivedData") && projPath.EndsWith(".app")) { _CompiledAppPath = projPath; break; } else if (projPath.Contains("DerivedData") && projPath.EndsWith(".app.dSYM")) { _CompiledAppPath = projPath.Replace(".dSYM", ""); break; } } numberOfAttemptsToFindTheCompiledApp++; System.Threading.Thread.Sleep(2000); } if (_CompiledAppPath == "") Log.CriticalError("Could not find the compiled app."); // launch instruments with bootstrap ProcessStartInfo instrumentsProcStartInfo = new ProcessStartInfo(); instrumentsProcStartInfo.FileName = "/usr/bin/instruments"; instrumentsProcStartInfo.Arguments = "-t " + instrumentsTemplatePath + " " + _CompiledAppPath + " -e UIASCRIPT " + bootstrapPath + " -e UIARESULTSPATH " + _iOSAutomationDirectory; instrumentsProcStartInfo.UseShellExecute = false; instrumentsProcStartInfo.RedirectStandardInput = true; try { _InstrumentsProc = Process.Start(instrumentsProcStartInfo); _CommandIndex = -1; } catch (Exception e) { Log.CriticalError(e.ToString()); _InstrumentsProc = null; } return true; }
static Device() { RealDevice = GetHardwareVersion(); IsRetina = UIScreen.MainScreen.Scale > 1.0; }