Categories
Apple User Help

Xamarin iOS app is not able to execute code when it is already minimized

I have a chat application, developed on the Xamarin.Forms platform, in which users can chat with each other. I have managed c# code and UI both in the shared project.

I have been facing problem since long in iOS platform. When the iOS app is running on screen, having foreground mode then the app can successfully receive a message which has been send by another user. When the app is running in the background mode and someone sends a message, I want to notify the user by using local notification (No Push remote notification – Because I think as my app is already running in minimized mode there is no need to wake up the app by implementing Push notification). Even I have implemented local notification successfully but the problem is,

When the iOS application heads to the background mode, the main thread (task) is paused so, when some user sends a message the app is not able to execute the code (when app is minimized) so that it won’t be able to show the local notification. But when the application is brought back to the foreground the thread/task get resumed and then ie shows up the local notification and also the message.

I already have selected the “Background fetch” property under Background Modes in Info.plist. I have also added below the line in my FinishedLaunching method

UIApplication.SharedApplication.SetMinimumBackgroundFetchInterval(UIApplication.BackgroundFetchIntervalMinimum);

I have implemented the performFetch method in AppDelegate as below,

public override void PerformFetch(UIApplication application, Action<UIBackgroundFetchResult> completionHandler)
    {
        completionHandler(UIBackgroundFetchResult.NewData);

        base.PerformFetch(application, completionHandler);         

    }

I have already worked and implemented code from below links, but didn’t worked for me.

My app is also having the audio-video calling functionality, So for the Background modes in info.plist, I have selected “Audio, Airplay and Picture in Picture”, “Voice over IP”, and “Background fetch” option.

I think my issue is relate to iOS Background processing, So, does anyone has idea what to do, to execute the code when app is already in minimized mode?

Leave a Reply

Your email address will not be published. Required fields are marked *