Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Handling "OnStop" Cleanup On iOS and Cross-Platform

$
0
0

I have a audio player (Cross Media Manager) that displays in the Status/Notification Bar anytime audio is played. But if you close the app mid-play of an audio file, the status/notification item remains.

On android I can do cleanup stuff in the OnPause/OnStop/OnDestroy methods.

But what about iOS? Since I'm not using any iOS views (it's all PCL)... I'm unsure of how to deallocate this stuff when the app closes.

NOTE: I've tried putting the cleanup in the OnSleep method of App.cs but it didn't work. The notification bar entry remained.

Here's my code for Android.

        protected override void OnDestroy()
        {
            audioCleanup();
            base.OnDestroy();
        }

        protected override void OnPause()
        {
            audioCleanup();
            base.OnPause();
        }

        protected override void OnStop()
        {
            audioCleanup();
            base.OnStop();
        }

        protected void audioCleanup()
        {
            if (CrossMediaManager.Current.AudioPlayer.Status != Plugin.MediaManager.Abstractions.Enums.MediaPlayerStatus.Stopped)
                CrossMediaManager.Current.AudioPlayer.Stop();


            if (CrossMediaManager.Current.MediaNotificationManager != null)
            {
                CrossMediaManager.Current.MediaNotificationManager.StopNotifications();
            }
        }
    }



Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>