Netmera Location Manager

The NMLocationManager is a feature that enables developers to track locations of devices, so these devices can take advantage of location based push notifications. With the NMLocationManager, you do not need to manually track the location of devices because the service automatically updates device locations through your app.

The Netmera Location Manager helps developers create push notification campaigns that take the location of a device into consideration. It also incorporates a time interval notification mechanism that send automated push messages to devices in a specified location, at specific time durations.

 Activating Location Tracking

By default, Netmera tracks users’ location changes using Apple’s significant-location tracking service, which provides a low-power location service for location updates. (Details can be found here)
However, if you need a more precise location tracking, you could start a location manager using NMLocationManager to track location with desired configuration.

Getting Location Authorization on iOS8 Devices

Core Location service API has received a major change about getting users’ permission in iOS 8. There are two authorisation types:

  • AlwaysAuthorization :

    Requests permission to use location services always (when app is either in background or foreground or not running).

  • WhenInUseAuthorization :

    Requests permission to use location services while the app is in the foreground.

There is a simple step that you must do in order to make Netmera get location updates in iOS 8 devices. You only have to put one of the NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription keys with proper description text strings. These texts will be prompted to user when requesting location permission.

Netmera will automatically call needed authorization request methods by checking the key that you put to your application’s Info.plist file.

Note:NSLocationAlwaysUsageDescription key will have precedence over NSLocationWhenInUseUsageDescription key. In other words, if you give both keys in Info.plist file, users will be asked to give always authorization.

Developers can easily incorporate the Location services on apps by using the following steps:

Step 1: Configure NMLocationManager

Developers are given free rein to customize feature parameters—distanceFilter and desiredAccuracy—as they wish. Apple constants and double metric values can also be utilized. This customization is optional. If developer does not set any value for these parameters, default values (kCLLocationAccuracyHundredMeters for distanceAccuracy and 10.0 meters for distanceFilter) will be used. Below is a sample code block explaining/showing the process:

[NMLocationManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
[NMLocationManager setDistanceFilter:20.0];

Step 2: Activate NMLocationManager

The next step is initializing NMLocationManager. This is done by passing NMLocationManager class with the “startLocationTracking” call method, a shown below:

[NMLocationManager startLocationTracking];

In order to track location when the application is on background, you must enable “Location updates” background mode for your application. Then, our location service will be informed for position changes of the device.

Step 3: Stop NMLocationManager

Netmera allows you to control all aspect of the location service, and you can easily stop the service by calling the “stopLocationTracking” method, as shown below:

[NMLocationManager stopLocationTracking];
Disabling Location Tracking

If you want to totally disable default location tracking for your application, you can set NO value for “SignificantLocationChangeTrackingEnabled” key in NetmeraSettings.plist  or disable it using the following line of code (The first way is recommended.):

[Netmera setSignificantLocationChangeTrackingEnabled:NO];

Preferred position of calling this method is at just after calling application:didFinishLaunchingWithOptions: delegate method. By this way, your application will not ask user for location tracking permissions.

You can also call it anywhere in your app lifecycle – e.g. put an option to enable/disable location tracking from settings menu of your application –, but in this case, users will be asked for location permission at application startup.

March 31, 2015 / parag

Recent Blog Posts
ROI based app marketing for your business
App Indexing: some insights
Categories