Forum Xamarin Xamarin.iOS

Screen locked

The screen is locked after accepting notification permissions. If I go back to the beginning (I put the app in the background) and go back to the screen it goes black. This only occurs in Release mode.. in Debug mode works successful..

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    The screen is locked after accepting notification permissions.

    Do you mean the screen turns off right after you click the notification permissions? I've never encountered it before can you post some screenshots to demonstrate it?

    If I go back to the beginning (I put the app in the background) and go back to the screen it goes black.

    Have you put some configurations in the WillEnterForeground event?
    Try to post a sample here to help us look into your issues.

  • Saantty44Saantty44 Member ✭✭

    @LandLu Hello, thanks for review.

    After tests, the screen is locked always with or without notification permissions (Only release mode). This only occurs first time, if I close the app and reopen it, it works successful.

    First, I enter in app. None component works.. then I back to main screen and resume the app (It's found on background). Then the app open with a black screen..


    Best regards, Santiago!

  • LandLuLandLu Member, Xamarin Team Xamurai

    Maybe you changed the window to some black or undefined instances after launching.
    We need your code to find out the real root cause.

  • Saantty44Saantty44 Member ✭✭

    @LandLu
    This is my LoginView (First page). The problem is only occurs one time.. If I close the app completely and restart, it works fine..

    private bool TokenExpired;
    
            public LoginView(bool TokenExpired)
            {
                InitializeComponent();
    
                this.TokenExpired = TokenExpired;
    
                App._LoginViewModel.ContainerLogo = absoluteLayout;
    
                this.BindingContext = App._LoginViewModel;
    
                MessagingCenter.Subscribe<LoginViewModel>(this, "RestError", (sender) =>
                {
                    DisplayAlert("Fallo en la autenticación.", "Ha ocurrido un error ineseprado", "OK");
                });
    
                MessagingCenter.Subscribe<LoginViewModel, string>(this, "LoginError", (sender, message) =>
                {
                    DisplayAlert("Fallo en la autenticación.", message, "OK");
                });
    
                MessagingCenter.Subscribe<LoginViewModel, string>(this, "DocutenError", (sender, message) =>
                {
                    DisplayAlert("Ha ocurrido un error.", message, "OK");
                });
    
                MessagingCenter.Subscribe<LoginViewModel, string>(this, "DocutenSinFirmar", (sender, message) =>
                {
                    DisplayAlert("Documento sin verificar.", message, "OK");
                });
    
                MessagingCenter.Subscribe<LoginViewModel, string>(this, "DocutenEnviado", (sender, message) =>
                {
                    DisplayAlert("Documento enviado.", "El documento ha sido enviado correctamente.\n" +
                        "Por favor, proceda a firmar el mismo para continuar utilizando la aplicación.\n" +
                        "Muchas gracias.", "OK");
                });
            }
    
            protected override void OnAppearing()
            {
                if (TokenExpired)
                    DisplayAlert("Fallo de autenticación.", "Aviso, por su seguridad la sesión ha caducado es necesario iniciar sesión otra vez.", "OK");
    
                base.OnAppearing();
    
            }
    
  • LandLuLandLu Member, Xamarin Team Xamurai

    How do you display this view in your app class?
    If you are using Forms how did you configure the AppDelegate on the iOS part?

  • Saantty44Saantty44 Member ✭✭

    @LandLu

    This is FinishedLaunching method !

    [Register("AppDelegate")]
        public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate, IUNUserNotificationCenterDelegate, IMessagingDelegate
        {
            //
            // This method is invoked when the application has loaded and is ready to run. In this 
            // method you should instantiate the window, load the UI into it and then make the window
            // visible.
            //
            // You have 17 seconds to return from this method, or iOS will terminate your application.
            //
            public override bool FinishedLaunching(UIApplication app, NSDictionary options)
            {
                UINavigationBar.Appearance.TintColor = UIColor.White;
                UINavigationBar.Appearance.TitleTextAttributes = new UIStringAttributes
                {
                    ForegroundColor = UIColor.White
                };
                UITabBar.Appearance.SelectedImageTintColor = UIColor.FromRGB(118, 53, 235);
                UITabBarItem.Appearance.SetTitleTextAttributes(
                    new UITextAttributes()
                    {
                        TextColor = UIColor.White
                    },
                    UIControlState.Selected);
    
                // Color of the unselected tab icon & text:
                UITabBarItem.Appearance.SetTitleTextAttributes(
                    new UITextAttributes()
                    {
                        TextColor = UIColor.White
                    },
                    UIControlState.Normal);
    
                global::Xamarin.Forms.Forms.Init();
                Rg.Plugins.Popup.Popup.Init();
                Xamarin.FormsMaps.Init();
                FFImageLoading.Forms.Platform.CachedImageRenderer.Init();
                ZXing.Net.Mobile.Forms.iOS.Platform.Init();
                ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
    
                Firebase.Core.App.Configure();
    
                LoadApplication(new App());
    
                // Register your app for remote notifications.
                if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
                {
                    var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;
                    UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) => {
    
                    });
    
                    // For iOS 10 display notification (sent via APNS)
                    UNUserNotificationCenter.Current.Delegate = this;
                    Messaging.SharedInstance.Delegate = this;
                }
                else
                {
                    // iOS 9 or before
                    var allNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
                    var settings = UIUserNotificationSettings.GetSettingsForTypes(allNotificationTypes, null);
                    UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
                }
    
                UIApplication.SharedApplication.RegisterForRemoteNotifications();
    
                return base.FinishedLaunching(app, options);
            }
    
  • LandLuLandLu Member, Xamarin Team Xamurai

    I can only guess some probable reasons as I can't test your project on my side.
    Was it caused by the network?
    I noticed that you configured the ssl using:

    ServicePointManager.ServerCertificateValidationCallback
    

    Will it block the UI parts if it fails?
    Try to remove all the initial code of third party libraries and only leave the init method of Forms. Will this issue occur?
    If you want us to find out more precise root cause try to open a support ticket and upload the project here:

    https://support.microsoft.com/en-us/supportforbusiness/productselection?sapId=211dd84f-3474-c3c5-79bf-66db630c92a6
    Microsoft promised to protect the personal information there and won't post any of your code on social media.

Sign In or Register to comment.