Search code examples
xamarin.formsxamarin.iosvisual-studio-mac

iOS version of app only runs on iPhone XS Max 12.1 Simulator


I'm using Visual Studio for Mac.

When I build and run my app on the iPhone simulator, it only runs on the iPhone XS Max simulator.

Every other simulated device (from XS Max all the way down to iPhone 6) will display the splash screen but then thorw a

Foundation.MonoTouchexception...NSInternalInconsistencyException Reason: Application windows are expected to have a root view controller at the end of the application launch

The only physical device I have to test with is an iPhone 6S Plus, but it throws the same exception as well.

I have tried cleaning and rebuilding, deleting bin and obj folders.

I checked the device log, but I haven't found anything yet to lead me to a solution (if you need the logs I can certainly provide).

Any ideas on what could cause this peculiar issue or what to keep an eye out for in the device logs that could help lead to a resolutoin?


Solution

  • This issue was being caused by my tokenExpiration on my App.xaml page.

    At some point when I tested my app on iPhone XS Max 12.1 the string was stored somewhere else so that when the app initializes this string isn't empty so var tokenDate = Convert.ToDateTime(tokenExpiration); will not throw an error.

    Then my if statement can be run successfully, and my application will have a base root view.

    However, for a new simulator that I haven't used before and haven't set the tokenExpiration string before when you want to retrieve this tokenExpiration it will return an empty string as the default setting.

    Then var tokenDate = Convert.ToDateTime(tokenExpiration); will throw an error as it can't convert the empty string.

    At last, my code will then run to my catch statement which means my application loses a base root view, and that is what causes my issue.

    Previous Code:

        try
        {
            TaskScheduler.UnobservedTaskException += (sender, e) => {
                Console.WriteLine(e.Exception.ToString(), Category.Exception, Priority.High);
            };
    
    
    
            await NavigationService.NavigateAsync("/LoginPage");
    
        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString(), Category.Exception, Priority.High);
        }
    

    Updated Code:

        var tokenExpiration = Preferences.Get("facebookTokenExpiration", string.Empty);
        if (tokenExpiration != null && tokenExpiration.Length > 0)
        {
            var tokenDate = Convert.ToDateTime(tokenExpiration);
            var tokenStatus = DateTime.Now.CompareTo(tokenDate);
            //Token is still active
            if (tokenExpiration != string.Empty & tokenStatus < 0)
            {
    
                await NavigationService.NavigateAsync("/MainTabbedPage?selectedTab=PuppyDetailsPage");
    
            }
            else
            {
                await NavigationService.NavigateAsync("/Login");
            }
        }
        else
        {
            await NavigationService.NavigateAsync("/MainTabbedPage?selectedTab=PuppyDetailsPage");
        }
    

    Edit: Thank you @LandLu a forums.xamarin.com for helping me to resolve this.