Advanced Functionality

Stop Monitoring Visits

If you need to stop monitoring the user’s visits (for example, if they opt out or turn off your background feature), you can turn off the Pilgrim SDK by calling:

PilgrimManager.shared().stop()

This will stop all Pilgrim activity. To resume Pilgrim, just call start() again.

Clear All History

In certain instances, you may want to clear a users visit history entirely from the device, including their Home and Work locations. An example of this may be a user logging out of your app. For this you should use:

PilgrimManager.shared().clearAllData()

You cannot call this when monitoring visits. You need to call stop() first.

Home and Work Detection

After 3-7 days of use the SDK will determine the user’s home and work location. You can see if this has been set by checking the hasHomeOrWork property.

PilgrimManager.shared().hasHomeOrWork()

Note: It's possible that you won't want to process any visits or only trust visits that have a 'High' confidence until home/work has been set. This is due to the fact that a user's home is not in our venue database, so we may be attributing 'home' visits to a venue nearby until we learn that this is in fact their home.

An example of this simple check is below:

func pilgrimManager(_ pilgrimManager: PilgrimManager, didVisit visit: Visit) {
    if pilgrimManager.hasHomeOrWork() {

        // Home and work are set. Lets print them out
        print(pilgrimManager.homeLocations)
        print(pilgrimManager.workLocations)

    } else if visit.confidence != .high {
        // Home and work aren't set and visit confidence isn't High
        // Depending on my application I might not want to trust this visit
    }

}

Other Possible Venues

By default, Pilgrim only returns the single venue that it believes the device is at. There is also a setting to return 4 alternate places (ordered by confidence) for arrival events. To enable these other venues, there is a checkbox on the Pilgrim Console of your Foursquare Developer account that you can turn on to begin to receiving these venues.

Once enabled, you can access the other places as follows:

func pilgrimManager(_ pilgrimManager: PilgrimManager, didVisit visit: Visit) {
    let otherVenues = visit.otherPossibleVenues
    // Do something with the alternate venues
}

Venue Harmonization

If you maintain your own venue database, you may want to know if a visit has occurred at one of those venues. We have a guide for venue harmonization in our API documentation, but we can also store a copy of the harmonization and return your venue Id in the Pilgrim visit callback. We enable this on a partner-by-partner basis, please contact us if you feel like this feature should be enabled for you. Once enabled, you will start seeing your venue Ids returned for visits where we have a mapping.

func pilgrimManager(_ pilgrimManager: PilgrimManager, didVisit visit: Visit) {
    let partnerId = visit.venue?.partnerVenueId
    // Do something with your own venue Id
}

Sign In