For iOS

To integrate with the DuopenGeofence Library on iOS, first you need to add the provided Package URL to your package dependencies tab on you applications

It is necessary for the user to allow in order 2 permissions:

  1. Location When in Use

  2. Location Always

These two permissions must be called in order, but NOT at the same time, because the "Always" permission needs the "When in Use" permission to be granted and the validation for that is not instant. We recommend to add a popup between these 2 requests, explaining to the user that selecting the "Always" option is recommended for a better experience on the app, this method create enough time to Swift to validate that information an request the second permission.

Here is an example on these two permission calls inside a generic ContentView

Once called these permissions, you can now call the functions to initialize the Geofence monitoring, here is an example on calling geofence monitoring from a ContentView File.

First the developer will need to assign the locationManager.delegate to the Geofence delegate, that will process the geofence transitions:

Now the geofence builder function can be called:

Parameters:

  • accessKey: A UUID provided for each application, mapping geofences to specific locations.

  • CPF: A unique identifier for logged users (e.g., “12345678900”).

    • NOTE: Please ensure that you are passing the correct user's CPF stored in your app.

  • Mode:

    • Mode.DEBUG: Sends location transitions to test endpoints (data not stored).

    • Mode.RELEASE: Stores data in the production database. Ensure Mode.RELEASE is used for production builds.

    • NOTE: Please ensure that if you are running on an emulator, use the mode.DEBUG parameter.

Example of Usage

Developers must ensure users grant both When in Use and Always location permissions.

Below is an implementation example in a generic ContentView:

Testing the Duopen Geofence Library in XCode Emulator

  1. On XCode simulator navigation bar, select Features.

  2. Select the option Location, from there, you can transition the device in or out of the geofence

    1. Select CustomLocation and set latitude and longitude from a point inside your known geofence monitored area to trigger "In" event

    2. Select other option rather than none or change you custom location to trigger the "Out" event.

  • You will be able to see the logs like the following if everything is working:

    • EVENT ~ Location: test-location | CPF: 12312312312| Status: IN | Mode: DEBUG

Last updated