Another update: The iLocationPlus library by
@marcel does support the Significant-Change Location Service. I have tested it and it works.
However, you can use the Significant-Change Location Service also with the standard iLocation library as follows:
Code:
Sub StartBackground(lm As LocationManager, MinimumDistance As Double)
Dim no As NativeObject = lm
no = no.GetField("manager")
If App.OSVersion >= 8 Then
no.RunMethod("requestAlwaysAuthorization", Null)
End If
no.SetField("distanceFilter", MinimumDistance)
Dim NativeMe As NativeObject = Me
Dim isSignLocAvailable As Boolean = NativeMe.RunMethod("isSignificantLocationAvailable", Null).AsBoolean
If isSignLocAvailable = True Then
no.RunMethod("startMonitoringSignificantLocationChanges",Null)
Else
'do something......
'no.RunMethod("startUpdatingLocation", Null)
End If
End Sub
#If OBJC
- (BOOL) isSignificantLocationAvailable {
if ([CLLocationManager significantLocationChangeMonitoringAvailable]) return YES;
return NO;
}
#end if
I added a verification (using inline OBJC) checking if the Significant-Change Location Service is available on the device. From what I have understood it requires a device with telephone-features.
The advantage with the Significant-Change Location Service is that it saves battery. Another advantage is that location gets updated even when the app has been killed/terminated by iOS or the user. It starts working again even when device has been rebooted. I have tested this and it works!
The disadvantage is that the location data gets updated less frequently. Apps can expect a notification as soon as the device moves 500 meters or more from its previous notification. It should not expect notifications more frequently than once every five minutes. If the device is able to retrieve data from the network, the location manager is much more likely to deliver notifications in a timely manner.
So it depends what you want to do with your locations.
To test without moving from your desk, make sure you are connected to a WIFI access point and then toggle Flight-mode on and off a few times and a location update should trigger in the
LocManager_LocationChanged sub.
EDIT: You may come across this if you are reading Apple's documentation:
If you start this service and your app is subsequently terminated, the system automatically relaunches the app into the background if a new event arrives. In such a case, the options dictionary passed to theapplication:willFinishLaunchingWithOptions: and application:didFinishLaunchingWithOptions: methods of your app delegate contains the key
UIApplicationLaunchOptionsLocationKey to indicate that your app was launched because of a location event. Upon relaunch, you must still configure a location manager object and call this method to continue receiving location events. When you restart location services, the current event is delivered to your delegate immediately. In addition, the
location property of your location manager object is populated with the most recent location object even before you start location services.
so it seemed I needed to get hold of the
UIApplicationLaunchOptionsLocationKey in order to restart the Significant-Change Location Service after the app was killed/terminated by iOS or the user (or if the device was rebooted). However, I noted that even if I don't look for the presence of the UIApplicationLaunchOptionsLocationKey (its value will be 1) and don't do something with it, the app will restart nicely and continue working. If you, however, are interested in getting the UIApplicationLaunchOptionsLocationKey, you can do so by using the following code in the AppStart event (thanks to Erel for explaining how):
Code:
Dim mymap As Map
mymap.Initialize
mymap = App.LaunchOptions
For Each key As String In mymap.Keys
If key = "UIApplicationLaunchOptionsLocationKey" Then
Log("Key is : " & key & " and the value is: " & mymap.Get(key))
End If
Next
But as I said (and as far as I understand), it is not really needed.