void ChangePhilipsHueStatus() { if ((philipsHue == null) || ((philipsHue != null) && (philipsHue.IsConnected == false))) { string deviceName = string.Empty; string hueAppKey = string.Empty; gameLayer.GamePaused = true; if (String.IsNullOrWhiteSpace(userDefaults.StringForKey(DEVICE_NAME)) == false) { deviceName = userDefaults.StringForKey(DEVICE_NAME); } if (String.IsNullOrWhiteSpace(userDefaults.StringForKey(HUE_APP_KEY_KEY)) == false) { hueAppKey = userDefaults.StringForKey(HUE_APP_KEY_KEY); } if (String.IsNullOrWhiteSpace(userDefaults.StringForKey(HUE_NOTIFICATION_SHOWED_KEY)) == true) { UIAlertController philipsHueConnectionAlert = UIAlertController.Create("Philips Hue Connection", "Connecting the app to Philips Hue color bulbs adds an extra dimension to the gameplay. If you own one, " + "press the link button on your Philips Hue bridge within " + HUE_BRIDGE_LOCATOR_TIMEOUT.ToString() + " seconds to check it out!", UIAlertControllerStyle.Alert); philipsHueConnectionAlert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, (connectionOK) => { philipsHue = new PhilipsHue(APP_NAME, deviceName, hueAppKey, HUE_BRIDGE_LOCATOR_TIMEOUT); ShowActivityIndicator(true); philipsHue.Connect(PhilipsHueConnectionAttemptComplete); philipsHueConnectionAlert.DismissViewController(true, null); })); philipsHueConnectionAlert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Default, (connectionCancel) => { philipsHueConnectionAlert.DismissViewController(true, null); ControlMenu("Show"); gameLayer.GamePaused = false; })); PresentViewController(philipsHueConnectionAlert, true, null); } else { philipsHue = new PhilipsHue(APP_NAME, deviceName, hueAppKey, HUE_BRIDGE_LOCATOR_TIMEOUT); ShowActivityIndicator(true); philipsHue.Connect(PhilipsHueConnectionAttemptComplete); } } else if ((philipsHue != null) && (philipsHue.IsConnected == true)) { philipsHue.Disconnect(); ChangePhilipsHueButton("Off"); ControlMenu("Show"); } }