Notification from EventDispatcher - fan-ADN/nendSDK-cocos2d-x GitHub Wiki

EventDispatcher will be in charge of sending notification from each ad.
It’s an optional to register EventDispatcher.

Banner Ad

Register EventDispatcher

Call the method named NADViewDelegateNotification
Ex.) Register and processing result of EventDispatcher for banner ads

Director::getInstance()->getEventDispatcher()->addCustomEventListener(NADViewDelegateNotification,[&](cocos2d::EventCustom *event) {
    int *intValue = (int *)event->getUserData();
    int resultCode = *intValue;
    switch (resultCode) {
    case FINISH_LOAD_AD: //only for iOS
        // finished loading ad
        break;
    case RECEIVE_AD:
        // succeed loading
        break;
    case FAIL_TO_RECEIVE_AD:
        // fail loading
        break;
    case CLICK_AD:
        // click banner ad
        break;
    case CLICK_INFORMATION:
        // click information button
        break;
    default:
        break;
    }
});

Cancel register EventDispatcher

Delete EventDispatcher from the method named NADViewDelegateNotification
Ex.) Cancel register EventDispatcher for banner ads

Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(NADViewDelegateNotification);

Register EventDispatcher for the event and spotID

Call the method named NADViewDelegateWithSpotIdNotification
Ex.) Register and processing result of EventDispatcher for the event and spotID

Director::getInstance()->getEventDispatcher()->addCustomEventListener(NADViewDelegateWithSpotIdNotification,[&](cocos2d::EventCustom *event) {
    int *resultArray = (int *)event->getUserData();
    int resultCode = resultArray[0];
    int spotId = resultArray[1];
    switch (resultCode) {
    case FINISH_LOAD_AD:      // only for iOS
        // finished loading ad
        break;
    case RECEIVE_AD:
        // succeed loading
        break;
    case FAIL_TO_RECEIVE_AD:
        // fail loading
        break;
    case CLICK_AD:
        // click banner ad
        break;
    case CLICK_INFORMATION:
        // click information button
        break;
    default:
        break;
    }
});

Cancel register EventDispatcher for the event and spotID

Delete EventDispatcher from the method named NADViewDelegateWithSpotIdNotification
Ex.) Cancel register and processing result of EventDispatcher for the event and spotID

Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(NADViewDelegateWithSpotIdNotification);

Icon Ad ※ Only for Android

Register EventDispatcher

Call the method named NADIconLoaderDelegateNotification
Ex.) Register and processing result EventDispatcher for icon ads

Director::getInstance()->getEventDispatcher()->addCustomEventListener(NADIconLoaderDelegateNotification,[&](cocos2d::EventCustom *event) {
    int *intValue = (int *)event->getUserData();
    int resultCode = *intValue;
    switch (resultCode) {
    case RECEIVE_AD_ICON:
        // succeed loading
        break;
    case FAIL_TO_RECEIVE_AD_ICON:
        // fail loading
        break;
    case CLICK_AD_ICON:
        // click icon ad
        break;
    case CLICK_INFORMATION_ICON:
        // click information button
        break;
    default:
        break;
    }
});

Cancel register EventDispatcher

Delete EventDispatcher from the method named NADIconLoaderDelegateNotification
Ex.) Cancel register and processing result of EventDispatcher for icon ads

Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(NADIconLoaderDelegateNotification);

Register EventDispatcher for the event and spotID

Call the method named NADIconLoaderDelegateWithSpotIdNotification
Ex.) Register and processing result of EventDispatcher for the event and spotID for icon ad

Director::getInstance()->getEventDispatcher()->addCustomEventListener(NADIconLoaderDelegateWithSpotIdNotification,[&](cocos2d::EventCustom *event) {
    int *resultArray = (int *)event->getUserData();
    int resultCode = resultArray[0];
    int spotId = resultArray[1];
    switch (resultCode) {
    case RECEIVE_AD_ICON:
        // succeed loading
        break;
    case FAIL_TO_RECEIVE_AD_ICON:
        // fail loading
        break;
    case CLICK_AD_ICON:
        // click icon ad
        break;
    case CLICK_INFORMATION_ICON:
        // click information button
        break;
    default:
        break;
    }
});

Cancel register EventDispatcher for the event and spotID

Delete EventDispatcher from the method named NADIconLoaderDelegateWithSpotIdNotification
Ex.) Cancel register and processing result of EventDispatcher for the event and spotID of icon ad

Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(NADIconLoaderDelegateWithSpotIdNotification);

Interstitial Ad

Register EventDispatcher of the loading result

Call the method named NADInterstitialDelegateLoadResultNotification
Ex.) Register and processing result of EventDispatcher for the loading result of interstitial ads

Director::getInstance()->getEventDispatcher()->addCustomEventListener(NADInterstitialDelegateLoadResultNotification,[&](cocos2d::EventCustom *event) {
    int *intValue = (int *)event->getUserData();
    int resultCode = *intValue;
    switch (resultCode) {
    case FINISH_LOAD_AD_INTERSTITIAL:
        // finished loading ad
        break;
    case FAIL_AD_DOWNLOAD_INTERSTITIAL:
        // fail loading
        break;
    case INVALID_RESPONSE_TYPE_INTERSTITIAL:
        // unavailable ad type
        break;
    case FAIL_AD_REQUEST_INTERSTITIAL:
        // request failed
        break;
    case FAIL_AD_INCOMPLETE_INTERSTITIAL:  //※only for Android
        // unfinished loading
        break;
    default:
        break;
    }
});

Cancel register EventDispatcher of the loading result

Delete EventDispatcher from the method named NADInterstitialDelegateLoadResultNotification
Ex.) Cancel register and processing result of EventDispatcher for the loading result of interstitial ads

Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(NADInterstitialDelegateLoadResultNotification);

Register EventDispatcherfor the loading result and spotID ※function added from ver1.1.2

Call the method named NADInterstitialDelegateLoadResultWithSpotIdNotification
Ex.) Register and processing result of EventDispatcher for the loading result of and spotID

Director::getInstance()->getEventDispatcher()->addCustomEventListener(NADInterstitialDelegateLoadResultWithSpotIdNotification,[&](cocos2d::EventCustom *event) {
    int *resultArray = (int *)event->getUserData();
    int resultCode = resultArray[0];
    int spotId = resultArray[1];
    switch (resultCode) {
    case FINISH_LOAD_AD_INTERSTITIAL:
        // finished loading ad
        break;
    case FAIL_AD_DOWNLOAD_INTERSTITIAL:
        // fail loading
        break;
    case INVALID_RESPONSE_TYPE_INTERSTITIAL:
        // unavailable ad type
        break;
    case FAIL_AD_REQUEST_INTERSTITIAL:
        // request failed
        break;
    case FAIL_AD_INCOMPLETE_INTERSTITIAL:  //※only for Android 
        // unfinished loading
        break;
    default:
        break;
    }
});

Cancel register EventDispatcherfor the loading result and spotID ※function added from ver1.1.2

Delete EventDispatcher from the method named NADInterstitialDelegateLoadResultWithSpotIdNotification
Ex.) Cancel register and processing result of EventDispatcher for the loading result of and spotID

Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(NADInterstitialDelegateLoadResultWithSpotIdNotification);

Register EventDispatcher for the displaying result

Call the method named NADInterstitialDelegateDisplayResultNotification
Ex.) Register and processing result of EventDispatcher for the displaying result of interstitial ads

Director::getInstance()->getEventDispatcher()->addCustomEventListener(NADInterstitialDelegateShowResultNotification,[&](cocos2d::EventCustom *event) {
    int *intValue = (int *)event->getUserData();
    int resultCode = *intValue;
    switch (resultCode) {
    case DISPLAY_SUCCESS:
        // succeed displaying
        break;
    case DISPLAY_ALREADY:
        // have already displayn
        break;
    case DISPLAY_FREQUENCY_NOT_REACHABLE:
        // have not reached ad’s frequency count
        break;
    case REQUEST_INCOMPLETE:
        // request failed
        break;
    case LOAD_INCOMPLETE:
        // request has not sent / sending request
        break;
    case DOWNLOAD_INCOMPLETE:
        // unfinished loading
        break;
    case CANNOT_DISPLAY:   //※only for iOS
        // Displaying ad failed
        break;
    default:
        break;
    }
});

Cancel register EventDispatcher for the displaying result

Delete EventDispatcher from the method named NADInterstitialDelegateDisplayResultNotification
Ex.) Cancel register EventDispatcher for the displaying result of interstitial ads

Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(NADInterstitialDelegateShowResultNotification);

Register EventDispatcher for the displaying result and spotID ※function added from ver1.1.2

Call the method named NADInterstitialDelegateDisplayResultWithSpotIdNotification
Ex.) Register and processing result of EventDispatcher for the displaying result and spotID of interstitial ads

Director::getInstance()->getEventDispatcher()->addCustomEventListener(NADInterstitialDelegateShowResultWithSpotIdNotification,[&](cocos2d::EventCustom *event) {
    int *resultArray = (int *)event->getUserData();
    int resultCode = resultArray[0];
    int spotId = resultArray[1];
    switch (resultCode) {
    case DISPLAY_SUCCESS:
        // succeed displaying
        break;
    case DISPLAY_ALREADY:
        // have already displayn
        break;
    case DISPLAY_FREQUENCY_NOT_REACHABLE:
        // have not reached ad’s frequency count
        break;
    case REQUEST_INCOMPLETE:
        // request failed
        break;
    case LOAD_INCOMPLETE:
        // request has not sent / sending request
        break;
    case DOWNLOAD_INCOMPLETE:
        // unfinished loading
        break;
    case CANNOT_DISPLAY:   //※only for iOS
        // Displaying ad failed
        break;
    default:
        break;
    }
});

Cancel register EventDispatcher for the displaying result and spotID ※function added from ver1.1.2

Delete EventDispatcher from the method named NADInterstitialDelegateDisplayResultWithSpotIdNotification
Ex.) Cancel register EventDispatcher for the displaying result and spotID of interstitial ads

Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(NADInterstitialDelegateShowResultWithSpotIdNotification);

Register EventDispatcher for the click type

Call the method named NADInterstitialDelegateClickResultNotification Ex.) Register and processing result of EventDispatcher for click type interstitial ads

Director::getInstance()->getEventDispatcher()->addCustomEventListener(NADInterstitialDelegateClickResultNotification,[&](cocos2d::EventCustom *event) {
    int *intValue = (int *)event->getUserData();
    int resultCode = *intValue;
    switch (resultCode) {
    case CLICK_DOWNLOAD:
        // click download button
        break;
    case CLICK_CLOSE:
        // ×click other area than button
        break;
    case CLICK_INFORMATION_INTERSTITIAL:
        // click information button
        break;
    default:
        break;
    }
});

Cancel click type EventDispatcher registration

Delete EventDispatcher from the method named NADInterstitialDelegateClickResultNotification
Ex.) Cancel register EventDispatcher for click type interstitial ads

Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(NADInterstitialDelegateClickResultNotification);

Register Click type and spotID of EventDispatcher ※function added from ver1.1.2

Call the method named NADInterstitialDelegateClickResultWithSpotIdNotification
Ex.) Register and processing result of EventDispatcher for click type interstitial ads and spotID

Director::getInstance()->getEventDispatcher()->addCustomEventListener(NADInterstitialDelegateClickResultWithSpotIdNotification,[&](cocos2d::EventCustom *event) {
    int *resultArray = (int *)event->getUserData();
    int resultCode = resultArray[0];
    int spotId = resultArray[1];
    switch (resultCode) {
    case CLICK_DOWNLOAD:
        // click download button
        break;
    case CLICK_CLOSE:
        // ×click other area than button
        break;
    case CLICK_INFORMATION_INTERSTITIAL:
        // click other than button
        break;
    default:
        break;
    }
});

Cancel register EventDispatcher for click type interstitial ads and spotID ※function added from ver1.1.2

Delete EventDispatcher from the method named NADInterstitialDelegateClickResultWithSpotIdNotification
Ex.) Cancel register EventDispatcher for click type interstitial ads and spotID

Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(NADInterstitialDelegateClickResultWithSpotIdNotification);

Example of EventDispatcher Implementation

Implementation Example of Registration

void HelloWorld::addEventDispatcher()
{
    // Get notification from EventDispatcher
    // banner
    Director::getInstance()->getEventDispatcher()->addCustomEventListener(NADViewDelegateNotification,[&](cocos2d::EventCustom *event) {
        int *intValue = (int *)event->getUserData();
        int resultCode = *intValue;
        switch (resultCode) {
        case FINISH_LOAD_AD:      // only for iOS
            break;
        case RECEIVE_AD:
            break;
        case FAIL_TO_RECEIVE_AD:
            break;
        case CLICK_AD:
            break;
        case CLICK_INFORMATION:
            break;
        default:
            break;
        }
    });

    // icon  ※only for Android
    Director::getInstance()->getEventDispatcher()->addCustomEventListener(NADIconLoaderDelegateNotification,[&](cocos2d::EventCustom *event) {
        int *intValue = (int *)event->getUserData();
        int resultCode = *intValue;
        switch (resultCode) {
        case RECEIVE_AD_ICON:
            break;
        case FAIL_TO_RECEIVE_AD_ICON:
            break;
        case CLICK_AD_ICON:
            break;
        case CLICK_INFORMATION_ICON:
            break;
        default:
            break;
        }
    });

    // Interstitial(Loading result)
    Director::getInstance()->getEventDispatcher()->addCustomEventListener(NADInterstitialDelegateLoadResultNotification,[&](cocos2d::EventCustom *event) {
        int *intValue = (int *)event->getUserData();
        int resultCode = *intValue;
        switch (resultCode) {
        case FINISH_LOAD_AD_INTERSTITIAL:
            break;
        case FAIL_AD_DOWNLOAD_INTERSTITIAL:
            break;
        case INVALID_RESPONSE_TYPE_INTERSTITIAL:
            break;
        case FAIL_AD_REQUEST_INTERSTITIAL:
            break;
        case FAIL_AD_INCOMPLETE_INTERSTITIAL:  // ※only for Android
            break;
        default:
            break;
        }
    });

    // Interstitial(Displaying result)
    Director::getInstance()->getEventDispatcher()->addCustomEventListener(NADInterstitialDelegateShowResultNotification,[&](cocos2d::EventCustom *event) {
        int *intValue = (int *)event->getUserData();
        int resultCode = *intValue;
        switch (resultCode) {
        case SHOW_SUCCESS:
            break;
        case SHOW_ALREADY:
            break;
        case SHOW_FREQUENCY_NOT_REACHABLE:
            break;
        case REQUEST_INCOMPLETE:
            break;
        case LOAD_INCOMPLETE:
            break;
        case DOWNLOAD_INCOMPLETE:
            break;
        case CANNOT_DISPLAY:   // ※only for iOS
            break;
        default:
            break;
        }
    });

    // Interstitial(click type)
    Director::getInstance()->getEventDispatcher()->addCustomEventListener(NADInterstitialDelegateClickResultNotification,[&](cocos2d::EventCustom *event) {
        int *intValue = (int *)event->getUserData();
        int resultCode = *intValue;
        switch (resultCode) {
        case CLICK_DOWNLOAD:
            break;
        case CLICK_CLOSE:
            break;
        case CLICK_INFORMATION_INTERSTITIAL:
            break;
        default:
            break;
        }
    });
}

Implementation Example of Cancel Registration

void HelloWorld::removeEventDispatcher()
{
    // Stop sending notification from EventDispatcher
    // banner
    Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(NADViewDelegateNotification);

    // icon ※ only for Android
    Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(NADIconLoaderDelegateNotification);

    // Interstitial
    Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(NADInterstitialDelegateLoadResultNotification);
    Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(NADInterstitialDelegateShowResultNotification);
    Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(NADInterstitialDelegateClickResultNotification);
}