iOS Location Services

Location services will allow you to add Geo-fence or iBeacon regions related to your app on the xtremepush platform. This allows you to analyse your app audiences, visits to your locations and trigger notifications when they enter/exit/dwell at your locations.

 

Enabling Locations services

In the standard integration described in the iOS integration guide Location Services are switched off.
It can be turned on using the setLocationEnabled method.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    
// ... [XPush setLocationEnabled:YES];
// ... [XPush applicationDidFinishLaunchingWithOptions:launchOptions]; return YES; }

You also need to add NSLocationAlwaysUsageDescription value to your Info.plist file. It will be shown to a user in the location permissions dialog.

 

iOS 11

 

On iOS 11 you need the following two usage description keys and associated usage description text for location to your plist:

NSLocationAlwaysAndWhenInUseUsageDescription

NSLocationWhenInUseUsageDescription

 Without both of these your App will simply not request location permission. You should explicitly state that your App needs the Always permission for whatever you use it for e.g. notifying you of special experiences at the stadium on game-day , adding reward points when you visit our store etc.

 

The opt-in prompt will now include an "Only While Using the App" option.

IMG_0364.PNG

 

Delaying Location Permissions Dialog

On iOS when your app uses location services it is often desirable to delay displaying the location permissions dialog. You may want to delay it until the user has logged in or until they have reached an appropriate section in the app where location is clearly required.  It is also good practice to display a value exchange screen prior to asking for location permissions explaining why you want to use location. This screen can contain App level Allow and Don't Allow buttons, that can set a local flag in the app if the user says no. If the user says no you don't have to show the OS dialog and that means if you want to ask them sometime in the future, you haven’t burned your chance with the OS permissions dialog. 

If you want to handle asking for location permissions yourself make sure to disable the xtremepush SDKs default behaviour of asking for location permissions using:

[XPush setAsksForLocationPermissions:NO];

Be sure to call the setAsksForLocationPermissions method before initialising xtremepush in the AppDelegate. When you're ready to ask for locations permissions use:

[XPush askForLocationPermissions];

 

Adding a Pre-permission Screen

Below is an example of how to show users an App level value exchange screen asking if they wants to allow access to location Now or Later is given below.

To handle the Don't Allow/Later button click:

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"LocationScreenLater"];
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"LocationScreenLaterCount"];

To handle Allow button click:

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"LocationScreenLater"];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"LocationScreenLaterCount"];
[XPush askForLocationPermissions];

In the applicationDidFinishLaunchingWithOptions:

// ...
[XPush setLocationEnabled:YES];
[XPush setAsksForLocationPermissions:NO];
[XPush applicationDidFinishLaunchingWithOptions:launchOptions];
// ...

bool showLocationScreen = NO;
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) { if ([[NSUserDefaults standardUserDefaults] boolForKey:@"LocationScreenLater"]) { NSInteger locationLater = [[NSUserDefaults standardUserDefaults] integerForKey:@"LocationScreenLaterCount"]; locationLater = locationLater + 1; [[NSUserDefaults standardUserDefaults] setInteger:locationLater forKey:@"LocationScreenLaterCount"]; if (locationLater >= 5) { showLocationScreen = YES; } } else {
showLocationScreen = YES;
}
}

if (showLocationScreen) {
// Do show location permissions screen
}

 

Have more questions? Submit a request

0 Comments

Article is closed for comments.