Skip to content

Manual Content Handling

If you wish to manually handle the presentation of NearIT content you can have instances of our content, starting from the UNNotificationResponse delivered after the user taps a notification.

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    let isNearNotification = NearManager.shared.getContentFrom(response) { (content, trackingInfo, error) in
        if let content = content, let trackingInfo = trackingInfo {
            self.handleNearContent(content: content, trackingInfo: trackingInfo)
        }
    }
    completionHandler()
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
    BOOL isNearNotification = [[NITManager defaultManager] getContentFrom:response completion:^(NITReactionBundle * _Nullable content, NITTrackingInfo * _Nullable trackingInfo, NSError * _Nullable error) {
        if (content) {
            [self handleNearContent:content trackingInfo: trackingInfo];
        }
    }];
}

In your handleNearContent method you can cast the various contents and show them with our viewControlllers:

func handleNearContent(_ content: Any, trackingInfo: NITTrackingInfo? = nil) {
    if let content = content as? NITContent {
        let contentVC = NITContentViewController(content: content)
        contentVC.show()
    } else if let feedback = content as? NITFeedback {
        let feedbackVC = NITFeedbackViewController(feedback: feedback)
        feedbackVC.show()
    } else if let coupon = content as? NITCoupon {
        let couponVC = NITCouponViewController(coupon: coupon)
        couponVC.show()
    } else if let simple = content as? NITSimpleNotification {
        // there's no content attached to the system notification that was just pressed
    } else if let customJson = content as? NITCustomJSON {
        // handle your custom json
    }
}
- (void)handleNearContent:(NITReactionBundle*)aContent trackingInfo:(NITTrackingInfo*)trackingInfo {
    if ([aContent isKindOfClass:[NITContent class]]) {
        NITContent *content = aContent;
        NITContentViewController *vc = [[NITContentViewController alloc] initWithContent:content trackingInfo:trackingInfo];
        [vc show];
    } else if ([aContent isKindOfClass:[NITFeedback class]]) {
        NITFeedback *feedback = aContent;
        NITFeedbackViewController *vc = [[NITFeedbackViewController alloc] initWithFeedback:feedback];
        [vc show];
    } else if ([aContent isKindOfClass:[NITCoupon class]]) {
        NITCoupon *coupon = aContent;
        NITCouponViewController *vc = [[NITCouponViewController alloc] initWithCoupon:coupon];
        [vc show];
    } else if ([aContent isKindOfClass:[NITSimpleNotification class]]) {
        NITSimpleNotification *simpleContent = aContent;
        // there's no content attached to the system notification that was just pressed
    } else if ([aContent isKindOfClass:[NITCustomJSON class]]) {
        NITCustomJSON *customJSON = aContent;
        // handle your custom json
    }
}

Every object type has a notificationMessage public attribute and a id() getter method.

Content Delegate

You can parse and get all the content already casted and sent to an object implementing the NITContentDelegate protocol. When you have a content and its trackingInfo you can call the parseContent method like this:

// AppDelegate
manager.parseContent(content, trackingInfo: trackingInfo, contentDelegate: self)

extension AppDelegate: NITContentDelegate {
    func gotSimpleNotification(_ notification: NITSimpleNotification, trackingInfo: NITTrackingInfo) {

    }

    func gotContent(_ content: NITContent, trackingInfo: NITTrackingInfo) {

    }

    func gotCoupon(_ coupon: NITCoupon, trackingInfo: NITTrackingInfo) {

    }

    func gotFeedback(_ feedback: NITFeedback, trackingInfo: NITTrackingInfo) {

    }

    func gotCustomJSON(_ customJson: NITCustomJSON, trackingInfo: NITTrackingInfo) {

    }
}
[manager parseContent:content trackingInfo:trackingInfo contentDelegate:self];

class NearSDKManager:<NITContentDelegate> {
    - (void)gotSimpleNotification:(NITSimpleNotification*)notification trackingInfo:(NITTrackingInfo*)trackingInfo {
        // simple notification
    }

    - (void)gotContent:(NITContent*)content trackingInfo:(NITTrackingInfo*)trackingInfo {
        // content
    }

    - (void)gotCoupon:(NITCoupon*)coupon trackingInfo:(NITTrackingInfo*)trackingInfo {
        // coupon
    }

    - (void)gotFeedback:(NITFeedback*)feedback trackingInfo:(NITTrackingInfo*)trackingInfo {
        // feedback
    }

    - (void)gotCustomJSON:(NITCustomJSON*)customJson trackingInfo:(NITTrackingInfo*)trackingInfo {
        // custom json
    }
}