A community member has associated this post with a similar question:
Xamarin iOS - development app is deployed on IPhone, but I cannot start it

Only moderators can edit this content.

Xamarin Forms - prevent iOS storyboard from loading

Ganesh Gebhard 366 Reputation points
2023-01-22T14:20:57.5033333+00:00

I'm using Visual Studio for Windows to test a Xamarin Forms app on Android. Now I want to test it on an iPhone as well, which is possible by connecting the iPhone to my Windows system and using Xamarin Hot Restart. The app is deployed on the iPhone, but when I tap on the icon it starts for a brief moment and then it closes (like it crashes). Looking at the link sent here earlier, in the Limitations section, the cause of this issue might be described there:

"Storyboard and XIB files are not supported and the app may crash if it attempts to load these at runtime. Use the HOTRESTART preprocessor symbol to prevent this code from executing."

I do have a Storyboard and I think an XIB file, but I have no idea how to prevent it from loading. The storyboard is called in info.plist only and the XIB extension is called in the .storyboard file.

LaunchScreen.storyboard

User's image

Info.plist

enter image description here

The usage of the preprocessor symbol HOTRESTART is only for C# I believe. My question thus is: how can I use the processor symbol HOTRESTART to prevent the loading of storyboard and XIB files?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,294 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 26,316 Reputation points Microsoft Vendor
    2023-01-25T04:50:34.8966667+00:00

    Hello,

    how can I use the processor symbol HOTRESTART to prevent the loading of storyboard and XIB files?

    If you have a storyboard or XIB file, and you are using hot restart, you can refer to the following code:

    #if !HOTRESTART
     UIStoryboard Storyboard = UIStoryboard.FromName ("LaunchScreen", null);// if you are not using hot restart, you can get the Storyboard 
    UIViewController vc = Storyboard.InstantiateInitialViewController () as UIViewController;//Then the logic can be processed 
    #endif
    

    Your main purpose is to disable the LaunchScreen.storyboard when you are using hot restart.

    For this, you can open Info.plist with source code editor, then remove the UILaunchStoryboardName key to test.
    (Your app will not have a splash screen for now, you can add this key if you don't use hot restart)

    After that, you can uninstall the app in your device, clean the bin/obj folder, and deploy/debug the app again.

    For more details, you can refer to Xamarin.Forms splash screen - Xamarin | Microsoft Learn

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentationto enable e-mail notifications if you want to receive the related email notification for this thread.