partial void ActionLogin(UIButton sender) { if (!IsNetEnable()) { return; } if (Validate()) { System.Threading.ThreadPool.QueueUserWorkItem(delegate { ShowLoadingView(Constants.MSG_LOGIN); bool isSuccess = false; InvokeOnMainThread(() => { isSuccess = LoginUser(txtEmail.Text, txtPassword.Text); HideLoadingView(); if (isSuccess) { MainPageViewController mainVC = Storyboard.InstantiateViewController("MainPageViewController") as MainPageViewController; this.PresentViewController(mainVC, true, null); } else { ShowMessageBox(null, Constants.MSG_LOGIN_FAIL); } }); }); } }
async private void GoToMainPage(string deviceUDID) { AppSettings.Email = txtEmail.Text; AppSettings.Password = txtPassword.Text; AppSettings.Username = txtNickName.Text; AppSettings.DeviceUDID = deviceUDID; string userID = "0"; await Task.Run(() => { InvokeOnMainThread(() => { userID = GetUserID(); }); HideLoadingView(); }); if (userID == "0") //if the user not registered yet, go to register screen { ShowMessageBox(null, Constants.MSG_SIGNUP_FAIL); } else //if the user already registered, go to main screen { MainPageViewController mainVC = Storyboard.InstantiateViewController("MainPageViewController") as MainPageViewController; this.PresentViewController(mainVC, false, null); } //ThreadPool.QueueUserWorkItem(delegate //{ // BeginInvokeOnMainThread(delegate // { // //register device id to keychain // var s = new SecRecord(SecKind.GenericPassword) // { // Label = "Item Label", // Description = "Item description", // Account = "Account", // Service = "Service", // Comment = "Your comment here", // ValueData = deviceID, // Generic = NSData.FromString("foo") // }; // var err = SecKeyChain.Add(s); // if (err != SecStatusCode.Success && err != SecStatusCode.DuplicateItem) // ShowMessageBox(null, "Can't save device id to keychain"); // //NSUserDefaults.StandardUserDefaults.SetString(deviceID, "deviceId"); // NSUserDefaults.StandardUserDefaults.SetString(txtEmail.Text, "email"); // NSUserDefaults.StandardUserDefaults.SetString(txtPassword.Text, "password"); // MainPageViewController mainVC = this.Storyboard.InstantiateViewController("MainPageViewController") as MainPageViewController; // this.PresentViewController(mainVC, false, null); // }); //}); }
private void GotoMainIfAlreadyLoggedin() { if (AppSettings.UserID != "0" && AppSettings.UserID != null && AppSettings.UserID != "") { MainPageViewController mainVC = Storyboard.InstantiateViewController("MainPageViewController") as MainPageViewController; this.PresentViewController(mainVC, false, null); } else { InitViewController mainVC = Storyboard.InstantiateViewController("InitViewController") as InitViewController; this.PresentViewController(mainVC, false, null); } }