Introduction
The Leanplum iOS Location SDK provides a seamless way to implement location-based targeting and messaging in your iOS apps. This documentation will guide you through the installation and usage of the Leanplum iOS Location SDK.
Requirements
- iOS 10.0 or later
- Xcode 11.0 or later
- Swift 5.0 or later
Installation
Cocoapods
To install the Leanplum iOS Location SDK via Cocoapods, add the following to your Podfile:
# Podfile
use_frameworks!
target 'YourTargetName' do
pod 'Leanplum-iOS-Location', '~> 1.0'
end
Carthage
To install using Carthage, add the following to your Cartfile:
# Cartfile
github "Leanplum/Leanplum-iOS-Location" ~> 1.0
Manual
- Download the latest release of the Leanplum iOS Location SDK from the GitHub releases page.
- Copy the LeanplumLocation.framework file to your Xcode project.
- In your project settings, navigate to the General tab and add the LeanplumLocation.framework to the “Frameworks, Libraries, and Embedded Content” section.
Usage
Import
In your Swift file, import the LeanplumLocation module:
import LeanplumLocation
Location Permissions
Request the appropriate location permissions from users:
Always Authorization (Background Mode)
To request “Always” location authorization, add the following to your Info.plist:
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Your description here</string>
When In Use Authorization (Foreground Mode)
To request “When In Use” location authorization, add the following to your Info.plist:
<key>NSLocationWhenInUseUsageDescription</key>
<string>Your description here</string>
Location-Based Messaging
Leanplum allows you to engage users with location-based messages. To utilize this feature, follow these steps:
- Enable location messaging in the Leanplum dashboard.
- Implement the necessary code to enable location tracking and messaging in your app. Refer to the LeanplumLocation documentation for details.
- Define geofences or iBeacons in the Leanplum dashboard.
- Create messages or actions that will be triggered when users enter or exit defined geofences or iBeacon regions.
Location Tracking
Leanplum allows you to track user locations to provide targeted messaging. To enable location tracking:
- Initialize the LeanplumLocation tracking:
LeanplumLocation.shared.start()
Additional Configuration
Location Accuracy
By default, LeanplumLocation uses the highest location accuracy available on the device. To change the accuracy:
LeanplumLocation.shared.setLocationAccuracy(.bestForNavigation)
Location Updates
To customize the frequency of location updates:
// Set desired accuracy
LeanplumLocation.shared.setLocationAccuracy(.best)
// Set the desired distance filter in meters
LeanplumLocation.shared.setLocationDistanceFilter(100)
Conclusion
Congratulations! You have successfully integrated the Leanplum iOS Location SDK into your app. Now you can leverage location-based targeting and messaging to engage your users effectively.