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
EventDispatcher
Register 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;
}
});
EventDispatcher
Cancel register Delete EventDispatcher
from the method named NADViewDelegateNotification
Ex.) Cancel register EventDispatcher
for banner ads
Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(NADViewDelegateNotification);
EventDispatcher
for the event and spotID
Register 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;
}
});
EventDispatcher
for the event and spotID
Cancel register 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
EventDispatcher
Register 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;
}
});
EventDispatcher
Cancel register Delete EventDispatcher
from the method named NADIconLoaderDelegateNotification
Ex.) Cancel register and processing result of EventDispatcher
for icon ads
Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(NADIconLoaderDelegateNotification);
EventDispatcher
for the event and spotID
Register 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;
}
});
EventDispatcher
for the event and spotID
Cancel register 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
EventDispatcher
of the loading result
Register 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;
}
});
EventDispatcher
of the loading result
Cancel register 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);
EventDispatcherfor
the loading result and spotID ※function added from ver1.1.2
Register 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;
}
});
EventDispatcherfor
the loading result and spotID ※function added from ver1.1.2
Cancel register 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);
EventDispatcher
for the displaying result
Register 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;
}
});
EventDispatcher
for the displaying result
Cancel register Delete EventDispatcher
from the method named NADInterstitialDelegateDisplayResultNotification
Ex.) Cancel register EventDispatcher
for the displaying result of interstitial ads
Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(NADInterstitialDelegateShowResultNotification);
EventDispatcher
for the displaying result and spotID ※function added from ver1.1.2
Register 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);
EventDispatcher
for the click type
Register 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;
}
});
EventDispatcher
registration
Cancel click type Delete EventDispatcher
from the method named NADInterstitialDelegateClickResultNotification
Ex.) Cancel register EventDispatcher
for click type interstitial ads
Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(NADInterstitialDelegateClickResultNotification);
EventDispatcher
※function added from ver1.1.2
Register Click type and spotID of 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;
}
});
EventDispatcher
for click type interstitial ads and spotID ※function added from ver1.1.2
Cancel register Delete EventDispatcher
from the method named NADInterstitialDelegateClickResultWithSpotIdNotification
Ex.) Cancel register EventDispatcher
for click type interstitial ads and spotID
Director::getInstance()->getEventDispatcher()->removeCustomEventListeners(NADInterstitialDelegateClickResultWithSpotIdNotification);
EventDispatcher
Implementation
Example of 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);
}