AppboyKit (also known as the Objective-C SDK) is no longer supported and has been replaced by the Swift SDK. It will no longer receive new features, bug fixes, security updates, or technical support—however, messaging and analytics will continue to function as normal. To learn more, see Introducing the New Braze Swift SDK.
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.
For location tracking to work reliably in iOS 14 for users who give approximate location permission, you must update your SDK version to at least 3.26.1
.
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.