Get Started
PREREQUISITES
In order to implement the Movement SDK in your app, you must first complete the following:
- Movement SDK Access Enabled
- Foursquare Developer Account w/ ClientID + Secret
1. Register App Bundle ID
In order for the Movement SDK to authenticate with our server, you'll need to add your iOS Bundle ID to your Foursquare app's configuration.
Navigate to your Foursquare Developer Console and select your app, then:
Find your app's Bundle Identifier. This can be found in the Identity section of your project's General tab:
In your Foursquare Developer Console on the Movement SDK Settings page, paste your iOS Bundle ID in the iOS Bundle IDs field.
Note: you can add multiple bundle IDs delimited by commas.
- Save your changes.
2. Install the Movement SDK
Option 1 - Carthage
- Add the following to your
Cartfile:
binary "https://foursquare.jfrog.io/foursquare/movementsdk-ios/MovementSdk.json" ~> 4.0.0
Navigate to Carthage/Build/iOS and drag the
MovementSdk.frameworkfile into Xcode in the Link Binary With Libraries section.Add a run script with the following script:
/usr/local/bin/carthage copy-frameworksSet the Input Files to:
$(SRCROOT)/Carthage/Build/iOS/MovementSdk.frameworkLoad the MovementSDK library into any necessary files by adding
import MovementSdk.Build your project.
Option 2 - CocoaPods
If you don't already have CocoaPods initiated in your project, enter the following command into the terminal:
pod initAdd the following to your Podfile:
pod 'MovementSdk', '~> 4.0.1'
Enter the following command into the terminal:
pod install(If you experience errors, trypod update.)Load the MovementSDK library into any necessary files by adding
import MovementSdk.Build your project.
Option 3 - Swift Package Manager
- In Xcode, install the Movement SDK by navigating to File > Add Packages…
- In the prompt that appears, search for the Movement SDK with the following Package URL:
https://github.com/foursquare/movementsdk-ios-spm - Select the version of the Movement SDK you want to use. For new projects, we recommend using the newest version of the Movement SDK.
3. Configure the Movement SDK
a. Configure Permissions
Turn Background Modes to On in your project's Capabilities tab and enable the Location updates checkbox:
Add the following to your iOS permission strings in your project's Info.plist file:
- Privacy - Location Always Usage Description
- Privacy - Location Always and When In Use Usage Description
- Privacy - Location When In Use Usage Description
b. Configure your AppDelegate
Configure the Movement SDK by pasting the following code in the didFinishLaunchingWithOptions method of your AppDelegate. Be sure to replace CLIENT_ID and CLIENT_SECRET with your real API credentials.
MovementSdkManager.shared().configure(withConsumerKey: "CLIENT_ID", secret: "CLIENT_SECRET", delegate: self, completion: nil)
If you are leveraging the Movement SDK in conjunction with the Personalization API, include oauthToken parameter also:
MovementSdkManager.shared().configure(withConsumerKey: "CLIENT_ID", secret: "CLIENT_SECRET", oauthToken: "OAUTH_TOKEN", delegate: self, completion: nil)
c. Disable AdId transmission
If you're using the free tier or do not have a data sharing agreement, you don't need to transmit the phone's mobile AdId to Foursquare:
# before the configure call:
MovementSdkManager.shared().disableAdIdentitySharing = true
d. Conform to the Movement SDK Delegate
Have your AppDelegate conform MovementSdkManagerDelegate by pasting the following code:
extension AppDelegate : MovementSdkManagerDelegate {
func movementSdkManager(_ movementSdkManager: MovementSdkManager, handle visit: Visit) {
print("(visit.hasDeparted ? "Departure from" : "Arrival at") (visit.venue != nil ? visit.venue!.name : "Unknown venue."). Added an SDK visit at: (visit.displayName)")
}
func movementSdkManager(_ movementSdkManager: MovementSdkManager, handleBackfill visit: Visit) {
print("Backfill (visit.hasDeparted ? "departure from" : "arrival at") (visit.venue != nil ? visit.venue!.name : "Unknown venue."). Added an SDK backfill visit at: (visit.displayName)")
}
func movementSdkManager(_ movementSdkManager: MovementSdkManager, handle geofenceEvents: [GeofenceEvent]) {
geofenceEvents.forEach { geofenceEvent in
print(geofenceEvent)
}
}
func movementSdkManager(_ movementSdkManager: MovementSdkManager, handleUserState updatedUserState: UserState, changedComponents: UserStateComponent) {
switch changedComponents {
case .city:
print("Welcome to (updatedUserState.city)")
}
}
func movementSdkManager(_ movementSdkManager: MovementSdkManager, handle error: Error) {
print(error)
}
}
4. Initialize the Movement SDK
Once the SDK is configured and set up to handle location events, you need to request location permissions from your user and tell the SDK to start running by calling start when .authorizedAlways:
MovementSdkManager.shared().start()
Note: You must inform the user of how you are using these permissions and how it benefits them.
a. Request Foreground Location
The SDK allows you to actively request the device's current location manually when the app is in use:
MovementSdkManager.shared().getCurrentLocation { (currentLocation, error) in
// Example: currentLocation.currentPlace.venue.name
}
Optional Configurations
Adding Wifi Entitlement
As of iOS 13.0, the Movement SDK must be configured to access Wifi information via the Wifi Entitlement.
1. Editing the app configuration
Go to the Certificates, Identifiers & Profiles portal on the Apple Developer site, then click on Identifiers, then select the app identifier you want to add the Wifi Entitlement to.
2. Regenerate provisioning profiles
Still on the Certificates, Identifiers & Profiles portal, click on Profiles to list the provisioning profiles, you will need to regenerate any profile that was created for the app identifier updated in the previous step.
3. Update the app in Xcode
In Xcode, open the preferences pane (Xcode > Preferences) then select Accounts. Select your Apple ID and team, then click Download Manual Profiles. In Xcode's Signing and Capabilities pane, select + Capability and double click on Access Wifi Information. This will add the com.apple.developer.networking.wifi-info key to your Entitlements plist file.