async override public void ViewDidAppear(bool animated) { if (GeneralSettings.AutoLogin) { if (!string.IsNullOrEmpty(Joyces.Helpers.Settings.AccessToken) && !string.IsNullOrEmpty(Joyces.Helpers.Settings.UserEmail)) { //Kontrollerar om användaren redan har loggat in en gång. try { var bounds = UIScreen.MainScreen.Bounds; loadPop = new LoadingOverlay(bounds); View.Add(loadPop); System.Diagnostics.Debug.WriteLine("================LOGIN IOS BEFORE CALLS ================ " + DateTime.Now.ToString("HH:mm:ss.fff")); //string sAccessToken = Helpers.Settings.AccessToken; string sUserEmail = Joyces.Helpers.Settings.UserEmail; if (!string.IsNullOrEmpty(Joyces.Helpers.Settings.AccessToken) && !string.IsNullOrEmpty(sUserEmail)) { Joyces.Platform.AppContext.Instance.Platform.CustomerId = sUserEmail; var getCustomer = await RestAPI.GetCustomer(sUserEmail, Joyces.Helpers.Settings.AccessToken); if (getCustomer != null && getCustomer is Customer) { Joyces.Platform.AppContext.Instance.Platform.CustomerList = (Customer)getCustomer; var resp = await RestAPI.GetOffer(sUserEmail, Joyces.Helpers.Settings.AccessToken); if (resp != null && resp is List <Offer> ) { Joyces.Platform.AppContext.Instance.Platform.OfferList = (List <Offer>)resp; } else { Joyces.Platform.AppContext.Instance.Platform.OfferList = null; } resp = await RestAPI.GetNews(sUserEmail, Joyces.Helpers.Settings.AccessToken); if (resp != null && resp is List <Joyces.News> ) { Joyces.Platform.AppContext.Instance.Platform.NewsList = (List <Joyces.News>)resp; } else { Joyces.Platform.AppContext.Instance.Platform.NewsList = null; } Joyces.Platform.AppContext.Instance.Platform.MoreList = await RestAPI.GetMore(Joyces.Helpers.Settings.AccessToken); var x = new MenuTabBarController(this.Handle); x.PerformSegue("segueMenu", this); } else { Joyces.Helpers.Settings.AccessToken = string.Empty; Joyces.Helpers.Settings.UserEmail = string.Empty; return; } } System.Diagnostics.Debug.WriteLine("================LOGIN IOS AFTER CALLS ================ " + DateTime.Now.ToString("HH:mm:ss.fff")); } catch (Exception ex) { } } } }
//Login button async partial void BtnLogin_TouchUpInside(UIButton sender) { var bounds = UIScreen.MainScreen.Bounds; loadPop = new LoadingOverlay(bounds); View.Add(loadPop); string sUsername = txtName.Text; string sPassword = txtPassword.Text; var tokenModel = await RestAPI.GetUserToken(sUsername, sPassword); if (tokenModel != null && tokenModel is TokenModel) { //Om allt går som det ska, så ska den komma in hit! Joyces.Helpers.Settings.AccessToken = ((TokenModel)tokenModel).access_token; Joyces.Helpers.Settings.UserEmail = sUsername; Joyces.Platform.AppContext.Instance.Platform.CustomerId = sUsername; var getCustomer = await RestAPI.GetCustomer(sUsername, Joyces.Helpers.Settings.AccessToken); if (getCustomer == null) { Joyces.Helpers.Settings.AccessToken = string.Empty; Joyces.Helpers.Settings.UserEmail = string.Empty; UIAlertView _error = new UIAlertView(Lang.ERROR_HEADLINE, Lang.UNEXPECTED_ERROR, null, Lang.BUTTON_OK, null); _error.Show(); loadPop.Hide(); } else if (getCustomer is Customer) { //Always set new token here. ((TokenModel)tokenModel).access_token = Joyces.Helpers.Settings.AccessToken; Joyces.Platform.AppContext.Instance.Platform.CustomerList = (Customer)getCustomer; var resp = await RestAPI.GetOffer(sUsername, Joyces.Helpers.Settings.AccessToken); if (resp != null && resp is List <Offer> ) { Joyces.Platform.AppContext.Instance.Platform.OfferList = (List <Offer>)resp; } else { Joyces.Platform.AppContext.Instance.Platform.OfferList = null; } resp = await RestAPI.GetNews(sUsername, Joyces.Helpers.Settings.AccessToken); if (resp != null && resp is List <Joyces.News> ) { Joyces.Platform.AppContext.Instance.Platform.NewsList = (List <Joyces.News>)resp; } else { Joyces.Platform.AppContext.Instance.Platform.NewsList = null; } Joyces.Platform.AppContext.Instance.Platform.MoreList = await RestAPI.GetMore(Joyces.Helpers.Settings.AccessToken); loadPop.Hide(); Joyces.Helpers.Settings.UserAccountNo = Joyces.Platform.AppContext.Instance.Platform.CustomerList.accountNumber; var x = new MenuTabBarController(this.Handle); x.PerformSegue("segueMenu", this); } else if (getCustomer is AbalonErrors) { var localError = (AbalonErrors)getCustomer; Joyces.Helpers.Settings.AccessToken = string.Empty; Joyces.Helpers.Settings.UserEmail = string.Empty; UIAlertView _error = new UIAlertView(Lang.MESSAGE_HEADLINE, localError.message, null, Lang.BUTTON_OK, null); _error.Show(); loadPop.Hide(); return; } } else if (tokenModel != null && tokenModel is AbalonErrors) { //Hit kommer den om ett fel returneras från Abalon loadPop.Hide(); Joyces.Helpers.Settings.AccessToken = string.Empty; Joyces.Helpers.Settings.UserEmail = string.Empty; if (((AbalonErrors)tokenModel).error_description.Contains("PRE_AUTHENTICATION")) { ((AbalonErrors)tokenModel).error_description = Lang.NOT_ACTIVATED_MEMBER; } try { //TEMPORÄRT string strErrorDesc = ((AbalonErrors)tokenModel).error_description; strErrorDesc = strErrorDesc.Replace("Missing parameters", "Saknade parametrar").Replace("username", "Epost").Replace("password", "Lösenord"); ((AbalonErrors)tokenModel).error_description = strErrorDesc; strErrorDesc = strErrorDesc + ""; } catch (Exception eee) { } UIAlertView _error = new UIAlertView(Lang.MESSAGE_HEADLINE, ((AbalonErrors)tokenModel).error_description.Replace("@carbon.super", ""), null, Lang.BUTTON_OK, null); _error.Show(); } else { //Vid all sorts exception kommer den hit och visar UNEXPECTED_ERROR! loadPop.Hide(); Joyces.Helpers.Settings.AccessToken = string.Empty; Joyces.Helpers.Settings.UserEmail = string.Empty; UIAlertView _error = new UIAlertView(Lang.MESSAGE_HEADLINE, Lang.UNEXPECTED_ERROR, null, Lang.BUTTON_OK, null); _error.Show(); } }