Skip to content

Handle Json Content

NearIT allows you to receive JSON data as a recipe "What". To handle JSONs from the notification tap:

func userNotificationCenter(_ center: UNUserNotificationCenter, 
                                didReceive response: UNNotificationResponse, 
                                withCompletionHandler completionHandler: @escaping () -> Void) {
        let isNearNotification = NearManager.shared.showContentFrom(response) { (content, trackingInfo, error) in
            ...
            if let customJson = content as? NITCustomJSON {
                // handle the custom JSON
            }
        }
        completionHandler()
    }
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
    BOOL isNearNotification = [[NITManager defaultManager] showContentFrom:response completion:^(NITReactionBundle * _Nullable content, NITTrackingInfo * _Nullable trackingInfo, NSError * _Nullable error) {
        if (error) {
            // there was an error
        }
        if [content isKindOfClass:[NITCustonJSON class]] {
            // handle the custom json
        }
    }];
    completionHandler();
}