Skip to content


Location tracking for iOS

By default, Braze disables location tracking. We enable location tracking after the host application has opted into location tracking and gained permission from the user. Provided users have opted into location tracking, Braze will log a single location for each user on session start.

Enabling automatic location tracking

Starting with Braze iOS SDK v3.17.0, location tracking is disabled by default. You can enable automatic location tracking using the Info.plist file. Add the Braze dictionary to your Info.plist file. Inside the Braze dictionary, add the EnableAutomaticLocationCollection boolean subentry and set the value to YES. Note that prior to Braze iOS SDK v4.0.2, the dictionary key Appboy must be used in place of Braze.

You can also enable automatic location tracking at app startup time via the startWithApiKey:inApplication:withLaunchOptions:withAppboyOptions method. In the appboyOptions dictionary, set ABKEnableAutomaticLocationCollectionKey to YES. For example:

1
2
3
4
[Appboy startWithApiKey:@"YOUR-API_KEY"
          inApplication:application
      withLaunchOptions:options
      withAppboyOptions:@{ ABKEnableAutomaticLocationCollectionKey : @(YES) }];
1
2
3
4
Appboy.start(withApiKey: "YOUR-API-KEY",
                 in:application,
                 withLaunchOptions:launchOptions,
                 withAppboyOptions:[ ABKEnableAutomaticLocationCollectionKey : true ])

Passing location data to Braze

The following two methods can be used to manually set the last known location for the user.

1
2
3
4
[[Appboy sharedInstance].user setLastKnownLocationWithLatitude:latitude
                                                     longitude:longitude
                                            horizontalAccuracy:horizontalAccuracy];

1
2
3
4
5
6
[[Appboy sharedInstance].user setLastKnownLocationWithLatitude:latitude
                                                     longitude:longitude
                                            horizontalAccuracy:horizontalAccuracy
                                                      altitude:altitude
                                              verticalAccuracy:verticalAccuracy];

1
Appboy.sharedInstance()?.user.setLastKnownLocationWithLatitude(latitude: latitude, longitude: longitude, horizontalAccuracy: horizontalAccuracy)
1
Appboy.sharedInstance()?.user.setLastKnownLocationWithLatitude(latitude: latitude, longitude: longitude, horizontalAccuracy: horizontalAccuracy, altitude: altitude, verticalAccuracy: verticalAccuracy)

Refer to ABKUser.h for more information.

HOW HELPFUL WAS THIS PAGE?
New Stuff!