Forum Xamarin.iOS

Red bar is showing at the top of iPhone home screen when app is going to background

Hi All,

I have enabled one of the Background mode setting(Audio, Airplay and Picture in Picture) in Info.plist. i am getting red bar at top of Iphone home screen as soon as my app goes to background. please find the attached screenshot. Is it possible to hide that red bar in xamarin.IOS.

Answers

  • ColeXColeX Member, Xamarin Team Xamurai
    edited January 5

    The red bar shows up if the app go to background while audio is playing .

    To hide it you need to stop the audio before entering background , you can do it in method DidEnterBackground in AppDelegate .

    Refer to https://stackoverflow.com/a/11451024/8187800.


    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

  • mahipalReddyNareddymahipalReddyNareddy INMember ✭✭

    Hi colex,

    i have tried to stop the audio in DidEnterBackground method but still i am able to see red bar.

  • ColeXColeX Member, Xamarin Team Xamurai

    Is your app doing other things(e.g recording screen) at that time ?

    If so , stop them all .

  • mahipalReddyNareddymahipalReddyNareddy INMember ✭✭

    Hi colex,

    Yes, but i am stoping in didEnterbackground event but it is not stoping. i have tried stoping the audio any click event in app, it is working fine.

  • ColeXColeX Member, Xamarin Team Xamurai

    Can you post the code in didEnterbackground ? How you stop the audio ?

  • mahipalReddyNareddymahipalReddyNareddy INMember ✭✭

    var currentSession = AVAudioSession.SharedInstance();
    currentSession.SetCategory(AVAudioSessionCategory.Playback, AVAudioSessionCategoryOptions.MixWithOthers);
    currentSession.SetActive(false);

  • ColeXColeX Member, Xamarin Team Xamurai

    From iOS 13, we need to override the lifecycle method in SceneDelegate , check details in https://stackoverflow.com/questions/56508764/app-delegate-methods-arent-being-called-in-ios-13 .

    So move your code into the DidEnterBackground method in SceneDelegate .

    //SceneDelegate .cs
     [Export ("sceneDidEnterBackground:")]
    public void DidEnterBackground (UIScene scene)
    {
        //stop your audio here . 
    }
    
  • ColeXColeX Member, Xamarin Team Xamurai

    @mahipalReddyNareddy Have you solved the problem ?

Sign In or Register to comment.