how to close .net maui app on iOS

Nam Pham 126 Reputation points
2022-12-27T06:37:22.98+00:00

i want to close .NET MAUI App from code behind

i'm using Application.Current.Quit();

it works on Android but on iOS it doesn't work

Does anyone know how to close the app on iOS

many thanks

Developer technologies .NET .NET MAUI
{count} votes

3 answers

Sort by: Most helpful
  1. Nam Pham 126 Reputation points
    2023-01-03T10:13:32.417+00:00

    For anyone wants to shut down the app
    Use this function System.Environment.Exit(0);, it works on iOS

    4 people found this answer helpful.

  2. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 36,436 Reputation points Microsoft External Staff
    2022-12-28T06:34:13.063+00:00

    Hello @Nam Pham ,

    On iOS, you can use exist(0) to quit App. But in this way, the app has the risk of being rejected by the App store. (It's not recommended that app quit itself in the old App Store Review Guidelines, the latest App Store Review Guidelines - Apple Developer does not have these contents)

    With MAUI, you can use P/Invoke to consume a native library. For example:

    Click button to quit App

     private void OnCounterClicked(object sender, EventArgs e)  
          {  
      
    #if IOS  
            exit(0);  
    #else  
    Application.Current.Quit();  
      
    #endif  
        }  
    #if IOS  
        [DllImport("__Internal", EntryPoint = "exit")]  
        public static extern void exit(int status);  
    #endif  
    

    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 documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    2 people found this answer helpful.

  3. Tumi Tladi 26 Reputation points
    2023-01-01T13:17:30.163+00:00

    I personally advise against having an iOS app closing/shutting down because of the high risk of Apple rejecting your app during the review process but Apple advise that you redirect the user to a page that has all the necessary yet brief info of what could have happened and that you “gracefully” let the users terminate the app themselves. This is what I did on my app but I haven’t yet published to App Store.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.