iOS9 Notifications

With the following snippet, if your app is closed or in background, a system notification will be added to the Notification Center. If your app is in foreground, the notification will be shown inside the app.

// AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    ...
    let settings = UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil)
    application.registerUserNotificationSettings(settings)
}

// Manage tap on remote notifications
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
    let isNearNotification = NearManager.shared.processRecipe(userInfo, completion: { (content, trackingInfo, error) in
        if let content = content {
            self.handleNearContent(content: content)
        }
    })
}

// Manage tap on local notifications
func application(_ application: UIApplication, didReceive notification: UILocalNotification) {
    if let userInfo = notification.userInfo {
        let isNearNotification = NearManager.shared.processRecipe(userInfo, completion: { (content, trackingInfo, error) in
            if let content = content {
                self.handleNearContent(content: content)
            }
        })
    }
}

extension AppDelegate: NITManagerDelegate {
    ...
    // implement the optional method for iOS9 support
    func manager(_ manager: NearManager, alertWantsToShowContent content: Any, trackingInfo: NITTrackingInfo) {
        handleNearContent(content: content)
    }
}
// AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    ...
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil]];
}

// Manage tap on remote notifications
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    BOOL isNearNotification = [[NITManager defaultManager] processRecipeWithUserInfo:userInfo completion:^(NITReactionBundle * _Nullable content, NITTrackingInfo * _Nullable trackingInfo, NSError * _Nullable error) {
        if (content) {
            [self handleNearContent:content];
        }
    }];
}

// Manage tap on local notifications
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
    BOOL isNearNotification = [[NITManager defaultManager] processRecipeWithUserInfo:notification.userInfo completion:^(NITReactionBundle * _Nullable content, NITTrackingInfo * _Nullable trackingInfo, NSError * _Nullable error) {
        if (content) {
            [self handleNearContent:content];
        }
    }];
}

// NITManagerDelegate implementation
- (void)manager:(NITManager *)manager alertWantsToShowContent:(id)content trackingInfo:(NITTrackingInfo *)trackingInfo {
    [self handleNearContent:content];
}