iOS SDK
Setup the Woosmap Geofencing SDK using iOS SDK
The Woosmap Geofencing SDK allows you to monitor Geofences, track your user’s location and connect with the Woosmap Search and Distance APIs.
Learn how to integrate the iOS SDK below. You can also explore a part of the source code on GitHub to get deeper into how user location is collected.
Find Geofencing iOS SDK release notes on the Gitub repository for releases.
Install SDK
You can install the SDK in four different ways. Note that the SDK is small and adds less than 3 MB to your compiled app.
CocoaPods
Install CocoaPods, a dependency manager for Cocoa projects. If you don’t have an existing Podfile, run pod init in your project directory. Add the following to your Podfile:
For usage and installation instructions, visit their website. To integrate Woosmap Geofencing SDK into your Xcode project using CocoaPods, specify it in your Podfile
:
use_frameworks!
pod 'WoosmapGeofencing'
Swift Package Manager
In Xcode, go to File > Swift Packages > Add Package Dependency. Enter https://github.com/Woosmap/geofencing-ios-sdk-spm-release.git
for the Package Repository URL.
Carthage
Install Carthage. To include GeofenceSDK as a binary origin, add the following to your Cartfile:
binary "https://raw.githubusercontent.com/Woosmap/geofencing-ios-sdk-spm-release/master/WoosmapGeofencing.json" ~> 4.0.0
Then, run carthage update --platform iOS --use-xcframeworks
and drag Build/iOS/WoosmapGeofencing.xcframework into the Linked Frameworks and Libraries section of your target. Do not add the framework as an input to your copy-frameworks run script.
Dependencies
The SDK currently supports iOS 13 and higher.
Initialize SDK
Starting from SDK version 4, the WoosmapGeofencing
class has been renamed to WoosmapGeofenceManager
to prevent conflicts with the package name.
To retrieve your user’s location data when your app starts, follow these steps:
First, set delegate of protocol Location in the AppDelegate
method.
import UIKit
import CoreLocation
import WoosmapGeofencing
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let dataLocation = DataLocation()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
WoosmapGeofenceManager.shared.getLocationService().locationServiceDelegate = dataLocation
if (CLLocationManager.authorizationStatus() != .notDetermined) {
WoosmapGeofenceManager.shared.startMonitoringInBackground()
}
return true
}
}
In order to avoid loosing data, you also need to call startMonitoringInBackground
in the proper AppDelegate
method:
func applicationDidEnterBackground(_ application: UIApplication) {
if (CLLocationManager.authorizationStatus() != .notDetermined) {
WoosmapGeofenceManager.shared.startMonitoringInBackground()
}
}
To keep the SDK up to date with user’s location data, you need to call didBecomeActive
in the proper AppDelegate
method too.
func applicationDidBecomeActive(_ application: UIApplication) {
WoosmapGeofenceManager.shared.didBecomeActive()
// Restart any tasks that were paused (or not yet started) while the application was inactive.
// If the application was previously in the background, optionally refresh the user interface.
}
The SDK tracks position by default. To disable location collection, just change the value in the settings of the SDK as follows:
WoosmapGeofenceManager.shared.setTrackingEnable(enable: false)
Finally, to effectively retrieve the location data, add this in your class delegate:
public class DataLocation:LocationServiceDelegate {
public init() {}
public func tracingLocation(location: Location) {
NSLog("location: \(location)")
}
public func tracingLocationDidFailWithError(error: Error) {
NSLog("\(error)")
}
public func readLocations()-> [Location] {
return Locations.getAll()
}
public func eraseLocations() {
Locations.deleteAll()
}
}
Usage of CLRegions
Woosmap Geofencing iOS SDK uses CLRegion. To ensure that all apps can participate in region monitoring, Core Location prevents any single app from monitoring more than 20 regions simultaneously. Most of Woosmap Geofencing features use between 17 and 20 CLRegion. If you need to use some CLRegion for another feature, please declare a number of slot you want to protect:
/// A maximum of 3 regions can be released by the Geofencing SDK
WoosmapGeofenceManager.shared.setProtectedRegionSlot(2)