Forum Xamarin Xamarin.iOS

How to perform background processing of Xamarin's iOS

Please tell me how you can perform the processing at regular intervals in the iOS background .
In the emulator it If you return to the home screen is run, but in the case of a real machine(iPhone6) does not run .


 Xamarin Studio 6.0.2
 Xamarin.iOS 9.8.2.22
 iPhone6 (iOS9.3.3)


using System;
using System.Threading;
using CoreLocation;

namespace XXX.iOS
{
public class testLocationManager : CLLocationManagerDelegate
{
private Timer _timer;
private CLLocationManager locationManager;
public testLocationManager()
{
locationManager = new CLLocationManager();
if (CLLocationManager.LocationServicesEnabled)
{
locationManager.Delegate = this;
locationManager.DesiredAccuracy = CLLocation.AccurracyBestForNavigation;
locationManager.ActivityType = CLActivityType.Fitness;
locationManager.PausesLocationUpdatesAutomatically = false;
locationManager.DistanceFilter = 1.0;
locationManager.AllowsBackgroundLocationUpdates = true;
locationManager.RequestAlwaysAuthorization();
locationManager.StartUpdatingLocation();
_timer = new Timer(new TimerCallback(ThreadingTimerCallback));
_timer.Change(0, 1000);
}
}
private void didUpdateToLocation(CLLocation newLocation, CLLocation oldLocation)
{
Console.WriteLine(string.Format("Location {0} => {1}", newLocation.ToString(), oldLocation.ToString()));
}
private static void ThreadingTimerCallback(object args)
{
Console.WriteLine(string.Format("ThreadingTimerCallback:{0}", DateTime.Now.ToString()));
}
}
}


using Foundation;
using UIKit;

namespace XXX.iOS
{
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
testLocationManager a = null;
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
a = new testLocationManager();
global::Xamarin.Forms.Forms.Init();
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
}
}


Console Log
2016-08-06 20:52:11.477 XXX[2399:785672] ThreadingTimerCallback:2016/08/06 20:52:11
2016-08-06 20:52:12.414 XXX[2399:785674] ThreadingTimerCallback:2016/08/06 20:52:12
2016-08-06 20:52:13.417 XXX[2399:785672] ThreadingTimerCallback:2016/08/06 20:52:13
2016-08-06 20:52:14.422 XXX[2399:785672] ThreadingTimerCallback:2016/08/06 20:52:14

Answers

  • kenichiro246kenichiro246 JPMember

    Add Info

    <Info.plist>
    Background Modes
    Enable Background Modes checked
    -> LocationUpdates checked

Sign In or Register to comment.