WoosmapNow Framework uses iOS regionMonitoring.
The number of monitored zone are limited. Both your app and the phone system have limitations.
WoosmapNow is using a fair count of regions.
Beware of this information if your app is already using this iOS feature.
First you need to embed our Frameworks
Make sure your have the proper capabilities checked
You also need to define two keys in the Info.plist:
NSLocationAlwaysAndWhenInUseUsageDescription and NSLocationWhenInUseUsageDescription
Before in fact using tracking user locations you should ask your user to do so.
This must only be done the first time the app is launched with WoosmapNow or when the user wants to change his status, this setting is saved on our side.
You can do this using a simple view and a UISwitch :
@IBOutlet weak var trackingSwitch: UISwitch!
override func viewDidLoad() {
super.viewDidLoad()
self.trackingSwitch.isOn = Now.shared.getUserTracking()
}
@IBAction func trackingSwitchChanged(_ sender: UISwitch) {
Now.shared.updateUserTracking(tracking: sender.isOn)
}Calling startMonitoringInBackground before setting tracking will stop WoosmapNow execution.
If tracking is set to true and if your user has not yet authorized your app to fetch locations, WoosmapNow will ask for it and start monitoring location changes.
The first step that should always be done each time your app is launched (in Foreground AND Background) is to set your Woosmap Private Key.
This should be done as early as possible in your didFinishLaunchingWithOptions App Delegate.
Depending on your integration, you should call startMonitoringInBackground too. This method must also be called everytime your app is Launched.
import WoosmapNow
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
Now.shared.setPrivateKey(privateKey: "__YOUR_WOOSMAP_MOBILE_PRIVATE_KEY__")
if (CLLocationManager.authorizationStatus() != .notDetermined) {
Now.shared.startMonitoringInBackground()
}
return true
}In order to be sure to avoid loosing data, you also need to call willTerminate in the proper AppDelegate method :
func applicationWillTerminate(_ application: UIApplication) {
Now.shared.willTerminate()
}func applicationDidEnterBackground(_ application: UIApplication) {
if CLLocationManager.authorizationStatus() != .notDetermined {
Now.shared.startMonitoringInBackground()
}
}Too keep our SDK up to date with user's data we need to call didBecomeActive in the proper AppDelegate method too.
func applicationDidBecomeActive(_ application: UIApplication) {
Now.shared.didBecomeActive()
}To get notifications from Woosmap, you need to generate your certificates at https://developer.apple.com and upload them on https://console.woosmap.com.
You should already have checked Remote notification capabilies in the Setup.
If you haven't already, you should ask the user for permissions. Here is a snippet :
import WoosmapNow
import UserNotifications
if #available(iOS 10, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
UNUserNotificationCenter.current().requestAuthorization(options:[.badge, .alert, .sound]) { granted, error in }
} else {
UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: nil))
}
UIApplication.shared.registerForRemoteNotifications()You should have two methods in your AppDelegate : didFailToRegisterForRemoteNotificationsWithError and didRegisterForRemoteNotificationsWithDeviceToken.
You need to give Woosmap Now the notification token each time the AppDelegate.didRegisterForRemoteNotificationsWithDeviceToken is called :
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data){
Now.shared.setRemoteNotificationToken(remoteNotificationToken: deviceToken)
}If you want rich notifications (AKA with Image, subtitles and more...) you need to add a NotificationService Extension .
If you don't want to code your own, you can use the WoosmapNowNotifications framework we provide for default implementation. Add the framework to the NotificationExtension Service
And then, just extend WoosmapNowNotification class :
import UserNotifications
import WoosmapNowNotification
class NotificationService: WoosmapNowNotification {
}Woosmap is tagging its Notifications payload with a woosmap key in userInfo's dict.
If your app is already using a NotificationExtension you can filter received payload by handling only those without this flag.
WoosmapNow provides a method to notify our backends that the notification that we sent has been opened by the user.
userInfo is the notification payload.
It can be provided by the didReceiveRemoteNotification method from AppDelegate.
Now.shared.notificationOpened(userInfo: userInfo)Beware that this AppDelegate method is called only when the app received a remote notification AND is running (in background or foreground). This means that you should check for your App's current state.
Or it can be provided by the didFinishLaunchingWithOptions if your app wasn't running.
Now.shared.notificationOpened(userInfo: launchOptions![UIApplicationLaunchOptionsKey.remoteNotification])






