Skip to content

Manual Content Handling

If you wish to create a custom representation for NearIT content, you can manually handle the content instances.

In your handleNearContent method you can cast the various contents:

func handleNearContent(_ content: Any, trackingInfo: NITTrackingInfo? = nil) {
    if let content = content as? NITContent {
        // content with attachments
    } else if let feedback = content as? NITFeedback {
        // feedback
    } else if let coupon = content as? NITCoupon {
        // coupon
    } else if let simple = content as? NITSimpleNotification {
        // simple notification
    } else if let customJson = content as? NITCustomJSON {
        // custom json
    }
}
- (void)handleNearContent:(NITReactionBundle*)aContent trackingInfo:(NITTrackingInfo*)trackingInfo {
    if ([aContent isKindOfClass:[NITContent class]]) {
        NITContent *content = aContent;
        // content with attachments
    } else if ([aContent isKindOfClass:[NITFeedback class]]) {
        NITFeedback *feedback = aContent;
        // feedback
    } else if ([aContent isKindOfClass:[NITCoupon class]]) {
        NITCoupon *coupon = aContent;
        // coupon
    } else if ([aContent isKindOfClass:[NITSimpleNotification class]]) {
        NITSimpleNotification *simpleContent = aContent;
        // simple notification
    } else if ([aContent isKindOfClass:[NITCustomJSON class]]) {
        NITCustomJSON *customJSON = aContent;
        // 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
    }
}