# Foursquare

Integrate the Foursquare Movement SDK with your Airship implementation.

Airship can easily integrate with Foursquare's Movement SDK by associating
channels with Foursquare user identifiers. This allows a single user to be consistently
identified across both platforms.

## Foursquare Integration Requirements

* **Accounts**
   1. Foursquare
   1. Airship — Must include messaging
   
* **Airship project**
   * The Airship SDK must use the same user identity as the Foursquare SDK.

Associating the Foursquare Movement user identifiers with Airship channels can be accomplished
with the following code.

### Client Code: iOS

On iOS, associating a Foursquare Movement user identifier with an Airship channel should
be done inside a callback triggered by the channel created event. This is to ensure
the channel ID is set immediately once it's available.

```swift
// Observe the notification center event `ChannelCreated`
NotificationCenter.default.addObserver(self, selector: #selector(AppDelegate.updateUserID), name:AirshipNotifications.ChannelCreated.name, object: nil)

// In the notification callback set the userID on your Movement SDK Manager instance
func updateUserID() {
     if let channelID = UAirship.push().channelID, let _ = FSQMovementSdkManager.shared().userInfo {
         FSQMovementSdkManager.shared().userInfo!.setUserId(channelID)
     }
 }
```


```obj-c
// Observe the notification center event `ChannelCreated`
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(updateChannel)
                                             name:UAirshipNotificationChannelCreated.name
                                           object:nil];

// In the notification callback set the userID on your Movement SDK Manager instance
NSString channelID = [[UAirship push] channelID];

if (channelID) {
    [FSQMovementSdkManager.sharedManager.userInfo setUserId:channelID];
}
```


### Client Code: Android

On Android, associating a Foursquare Movement user identifier with an Airship channel should be
done inside a class extending `AirshipReceiver` that implements its `onChannelCreated`
function. This is to ensure the channel ID is set immediately once it's available.

```kotlin
private class MovementAirshipIntegration : AirshipChannelListener {
    override fun onChannelCreated(channelId: String) {
        val userInfo = UserInfo().apply {
            setUserId(channelId)
        }

        MovementSdk.get().setUserInfo(userInfo, persisted = true)
    }
}
```


## Configuring the Foursquare Integration 

In Airship:

1. Next to your project name, select the dropdown menu (
), then **Settings**.
1. Under **Project settings**, select **Partner Integrations**.
1. Select **Foursquare**.
1. Select **Configure** for the inbound integration and follow the onscreen instructions to:
	* Create [Custom Events](https://www.airship.com/docs/reference/glossary/#custom_event) and an authentication token. Foursquare uses the token to communicate with your project in Airship.
	* Configure Airship as a third-party integration in Foursquare.