Forum Xamarin.iOS
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Background service in iOS

SYLENDRABABUJRSYLENDRABABUJR USMember ✭✭

Hi ,

How to create a background service which will run periodically in background even if the app is in closed state...?

Tagged:

Answers

  • ColeXColeX Member, Xamarin Team Xamurai
    edited July 2019

    How to create a background service which will run periodically in background even if the app is in closed state...?

    In background state : refer iOS Backgrounding Techniques.

    In closed state : Impossible to achieve.

  • Imran_619Imran_619 Member ✭✭✭

    I'm doing something like this is my Xamarin Forms apps.

    public void execute()
    {
    var thread = new Thread(new ThreadStart(startAuthenticationProcess))
    {
    IsBackground = true
    };
    thread.Start();
    }
    private void startAuthenticationProcess()
    {
    Thread.Sleep(2000);
    if (!Utils.isNetworkAvailable(splashActivity))
    {
    splashActivity.RunOnUiThread(() => Utils.showToast(splashActivity, splashActivity.GetString(Resource.String.r30025)));
    splashActivity.FinishAffinity();
    }
    else
    {
    try
    {
    if (StringUtils.isBlank(strIPAdd) || (StringUtils.isNotBlank(strIPAdd) && (StringUtils.isBlank(strDbName) || "site".Equals(strDbName,StringComparison.OrdinalIgnoreCase))))
    {
    splashActivity.RunOnUiThread(() => DependencyService.Get().showAuthenticationDialog(new Command(() =>
    {
    var intent = new Intent(splashActivity, typeof(MainActivity));
    intent.PutExtra("startLoginActivity", false);
    splashActivity.StartActivity(intent);
    splashActivity.Finish();
    })));
    }
    else
    {
    gotoLoginScreen();
    }
    }
    catch (Exception e)
    {
    Log.Error(TAG, e.Message);
    }
    }
    }

    For more information on mobile app development you can visit ArStudio

Sign In or Register to comment.