Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ proj.win32/Release.*/

# others
cocos2d
Build-ios

.vscode/

Expand Down
262 changes: 262 additions & 0 deletions AppDelegate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
#include "AppDelegate.h"
#include "HelloWorldScene.h"

// #define USE_AUDIO_ENGINE 1
// #define USE_SIMPLE_AUDIO_ENGINE 1

#if USE_AUDIO_ENGINE && USE_SIMPLE_AUDIO_ENGINE
#error "Don't use AudioEngine and SimpleAudioEngine at the same time. Please just select one in your game!"
#endif

#if USE_AUDIO_ENGINE
#include "audio/include/AudioEngine.h"
using namespace cocos2d::experimental;
#elif USE_SIMPLE_AUDIO_ENGINE
#include "audio/include/SimpleAudioEngine.h"
using namespace CocosDenshion;
#endif

#include "AppsFlyer/AppsFlyerX.h"
#include "AppsFlyer/AppsFlyerXDeepLinkResult.h"
#include "../cocos2d/cocos/platform/CCPlatformMacros.h"

USING_NS_CC;

static cocos2d::Size designResolutionSize = cocos2d::Size(480, 320);
static cocos2d::Size smallResolutionSize = cocos2d::Size(480, 320);
static cocos2d::Size mediumResolutionSize = cocos2d::Size(1024, 768);
static cocos2d::Size largeResolutionSize = cocos2d::Size(2048, 1536);

AppDelegate::AppDelegate()
{
}

AppDelegate::~AppDelegate()
{
#if USE_AUDIO_ENGINE
AudioEngine::end();
#elif USE_SIMPLE_AUDIO_ENGINE
SimpleAudioEngine::end();
#endif
}

// if you want a different context, modify the value of glContextAttrs
// it will affect all platforms
void AppDelegate::initGLContextAttrs()
{
// set OpenGL context attributes: red,green,blue,alpha,depth,stencil
GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};

GLView::setGLContextAttrs(glContextAttrs);


}

// if you want to use the package manager to install more packages,
// don't modify or remove this function
static int register_all_packages()
{
return 0; //flag for packages manager
}

static void onConversionDataSuccess(cocos2d::ValueMap installData) {
CCLOG("%s", "AppDelegate.cpp got conversion data!");
std::string gcd = "Conversion Data : ";

for (auto &t : installData){

CCLOG("%s - %s", t.first.c_str(), t.second.asString().c_str());
gcd.append(t.first.c_str());
gcd.append(" : ");
gcd.append(t.second.asString().c_str());
gcd.append("\n");
}
// auto gcdStr = gcd;
// auto currentScene = Director::getInstance()->getRunningScene();
// auto size = Director::getInstance()->getVisibleSize();
// Vec2 origin = Director::getInstance()->getVisibleOrigin();
// auto myLabel = Label::createWithSystemFont(gcd.c_str(), "Arial", 6);
// myLabel->setPosition(Vec2(origin.x + 80, origin.y + size.height - 180));
// //myLabel->setHeight( origin.y + size.height - 180);
// //myLabel->setHorizontalAlignment(cocos2d::TextHAlignment::CENTER);
// currentScene->addChild(myLabel,1);


}

static void onConversionDataFail(cocos2d::ValueMap map) {
for (auto &t : map){
CCLOG("%s - %s", t.first.c_str(), t.second.asString().c_str());
}
}

static void onAppOpenAttribution(cocos2d::ValueMap map) {
for (auto &t : map){
CCLOG("%s - %s", t.first.c_str(), t.second.asString().c_str());
}
}

static void onAppOpenAttributionFailure(cocos2d::ValueMap map) {
for (auto &t : map){
CCLOG("%s - %s", t.first.c_str(), t.second.asString().c_str());
}
}

static void didResolveDeepLink(AppsFlyerXDeepLinkResult result){
CCLOG("%s", "AppDelegate.cpp got ddl!");
std::string ddl = "Deep link data is \n";
switch (result.status) {
case NOTFOUND:
CCLOG("deep link not found");
break;
case FOUND:
if (!result.deepLink.empty()){
if (!result.getMediaSource().empty()) {
CCLOG("Media source is %s", result.getMediaSource().c_str());
}
for (auto &t : result.deepLink){
CCLOG("%s - %s", t.first.c_str(), t.second.asString().c_str());
ddl.append(t.first.c_str());
ddl.append(" : ");
ddl.append(t.second.asString().c_str());
ddl.append("\n");
}
auto currentScene = Director::getInstance()->getRunningScene();
auto child = currentScene->getChildByTag(1);
if (child != NULL)
currentScene->removeChildByTag(1);
auto size = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
auto myLabel = Label::createWithSystemFont(ddl.c_str(), "Arial", 6);
myLabel->setPosition(Vec2(origin.x + 80, origin.y + size.height - 180));
//myLabel->setHeight( origin.y + size.height - 180);
//myLabel->setHorizontalAlignment(cocos2d::TextHAlignment::CENTER);
currentScene->addChild(myLabel,1, 1);
}
}

}

bool AppDelegate::applicationDidFinishLaunching() {

AppsFlyerX::stop(false);
// AppsFlyerX::enableTCFDataCollection(true);
AppsFlyerX::setIsDebug(true);
// AppsFlyerX::setConsentData(AppsFlyerXConsent::initNonGDPRUser());
// AppsFlyerX::setConsentData(AppsFlyerXConsent::initForGDPRUser(true,true));
//AppsFlyerX::setMinTimeBetweenSessions(9);
AppsFlyerX::setAppsFlyerDevKey("devkey");

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
// // In case you want to use manual mode.
// AppsFlyerX::setManualStart(true);
// //
AppsFlyerX::setAppleAppID("appleAppId");
// AppsFlyerX::waitForATTUserAuthorizationWithTimeoutInterval(60);

#endif
// std::vector<std::string> partners;
// partners.push_back("facebook_int");
// partners.push_back("googleadwords_int");
// AppsFlyerX::sharingFilter(partners);
// AppsFlyerX::sharingFilterForAllPartners();
AppsFlyerX::setOnConversionDataSuccess(onConversionDataSuccess);
AppsFlyerX::setOnConversionDataFail(onConversionDataFail);
AppsFlyerX::setOnAppOpenAttribution(onAppOpenAttribution);
AppsFlyerX::setOnAppOpenAttributionFailure(onAppOpenAttributionFailure);
AppsFlyerX::setDidResolveDeepLink(didResolveDeepLink);
ValueMap data;
data["thePartnerId"] = "abcd";
data["Item_id"] = 1;
data["isLegacy"] = false;
AppsFlyerX::setPartnerData("partnerID", data);

// AppsFlyerX::logEvent(AFEventPurchase, {{ "key1", cocos2d::Value("value1")},
// { "key2", cocos2d::Value("value2")}});
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// remove this to use manual mode.
AppsFlyerX::start();
//
#endif

// initialize director
auto director = Director::getInstance();
auto glview = director->getOpenGLView();
if(!glview) {
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
glview = GLViewImpl::createWithRect("AppsFlyerCocos2dX", cocos2d::Rect(0, 0, designResolutionSize.width, designResolutionSize.height));
#else
glview = GLViewImpl::create("AppsFlyerCocos2dX");
#endif
director->setOpenGLView(glview);
}

// turn on display FPS
director->setDisplayStats(true);

// set FPS. the default value is 1.0/60 if you don't call this
director->setAnimationInterval(1.0f / 60);

// Set the design resolution
glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
auto frameSize = glview->getFrameSize();
// if the frame's height is larger than the height of medium size.
if (frameSize.height > mediumResolutionSize.height)
{
director->setContentScaleFactor(MIN(largeResolutionSize.height/designResolutionSize.height, largeResolutionSize.width/designResolutionSize.width));
}
// if the frame's height is larger than the height of small size.
else if (frameSize.height > smallResolutionSize.height)
{
director->setContentScaleFactor(MIN(mediumResolutionSize.height/designResolutionSize.height, mediumResolutionSize.width/designResolutionSize.width));
}
// if the frame's height is smaller than the height of medium size.
else
{
director->setContentScaleFactor(MIN(smallResolutionSize.height/designResolutionSize.height, smallResolutionSize.width/designResolutionSize.width));
}

register_all_packages();

// create a scene. it's an autorelease object
auto scene = HelloWorld::createScene();

// run
director->runWithScene(scene);

return true;
}

// This function will be called when the app is inactive. Note, when receiving a phone call it is invoked.
void AppDelegate::applicationDidEnterBackground() {
Director::getInstance()->stopAnimation();

AppsFlyerX::didEnterBackground();

#if USE_AUDIO_ENGINE
AudioEngine::pauseAll();
#elif USE_SIMPLE_AUDIO_ENGINE
SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
SimpleAudioEngine::getInstance()->pauseAllEffects();
#endif
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground() {
Director::getInstance()->startAnimation();

//CCLOG("%s", "~+~+~+~+~ applicationWillEnterForeground ~+~+~+~+~");

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// remove this to use manual mode.
AppsFlyerX::start();
//
#endif

#if USE_AUDIO_ENGINE
AudioEngine::resumeAll();
#elif USE_SIMPLE_AUDIO_ENGINE
SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
SimpleAudioEngine::getInstance()->resumeAllEffects();
#endif
}
40 changes: 40 additions & 0 deletions AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef _APP_DELEGATE_H_
#define _APP_DELEGATE_H_

#include "cocos2d.h"

/**
@brief The cocos2d Application.

Private inheritance here hides part of interface from Director.
*/
class AppDelegate : private cocos2d::Application
{
public:
AppDelegate();
virtual ~AppDelegate();

virtual void initGLContextAttrs();

/**
@brief Implement Director and Scene init code here.
@return true Initialize success, app continue.
@return false Initialize failed, app terminate.
*/
virtual bool applicationDidFinishLaunching();

/**
@brief Called when the application moves to the background
@param the pointer of the application
*/
virtual void applicationDidEnterBackground();

/**
@brief Called when the application reenters the foreground
@param the pointer of the application
*/
virtual void applicationWillEnterForeground();
};

#endif // _APP_DELEGATE_H_

32 changes: 25 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,31 @@ endif()

# add cross-platforms source files and header files
list(APPEND GAME_SOURCE
Classes/AppsFlyer/AFSDKXPurchaseDetails.cpp
Classes/AppsFlyer/AFSDKXValidateAndLogResult.cpp
Classes/AppsFlyer/AFXAdRevenueData.cpp
Classes/AppsFlyer/AppsFlyerX.cpp
Classes/AppDelegate.cpp
Classes/HelloWorldScene.cpp
Classes/AppsFlyer/AppsFlyerXApple.mm
Classes/AppsFlyer/AppsFlyerXAppleDeepLinkDelegate.mm
Classes/AppsFlyer/AppsFlyerXAppleDelegate.mm
Classes/AppsFlyer/AppsFlyerXAppleHelper.mm
Classes/AppsFlyer/AppsFlyerXConsent.cpp
Classes/AppsFlyer/AppsFlyerXDeepLinkResult.cpp
)
)

list(APPEND GAME_HEADER
Classes/AppsFlyer/AFSDKXPurchaseDetails.h
Classes/AppsFlyer/AFSDKXValidateAndLogResult.h
Classes/AppsFlyer/AFXAdRevenueData.h
Classes/AppsFlyer/AppsFlyerX.h
Classes/AppDelegate.h
Classes/HelloWorldScene.h
Classes/AppsFlyer/AppsFlyerXApple.h
Classes/AppsFlyer/AppsFlyerXAppleDeepLinkDelegate.h
Classes/AppsFlyer/AppsFlyerXAppleDelegate.h
Classes/AppsFlyer/AppsFlyerXAppleHelper.h
Classes/AppsFlyer/AppsFlyerXDeepLinkResult.h
)
Classes/AppsFlyer/AppsFlyerXMacro.h
Classes/AppsFlyer/EmailCryptTypeX.h
)

if(ANDROID)
list(APPEND GAME_SOURCE
Expand Down Expand Up @@ -102,6 +116,8 @@ elseif(APPLE)
list(APPEND GAME_HEADER
proj.ios_mac/ios/AppController.h
proj.ios_mac/ios/RootViewController.h
proj.ios_mac/ios/HelloWorldScene.h
proj.ios_mac/ios/AppDelegate.h
)

set(APP_UI_RES
Expand All @@ -115,6 +131,8 @@ elseif(APPLE)
proj.ios_mac/ios/AppController.mm
proj.ios_mac/ios/RootViewController.mm
proj.ios_mac/ios/Prefix.pch
proj.ios_mac/ios/HelloWorldScene.cpp
proj.ios_mac/ios/AppDelegate.cpp
${APP_UI_RES}
)
elseif(MACOSX)
Expand Down Expand Up @@ -159,7 +177,7 @@ if(APPLE)
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/proj.ios_mac/mac/Info.plist"
)
elseif(IOS)
cocos_pak_xcode(${APP_NAME} INFO_PLIST "iOSBundleInfo.plist.in")
#cocos_pak_xcode(${APP_NAME} INFO_PLIST "iOSBundleInfo.plist.in")
# set_xcode_property(${APP_NAME} ASSETCATALOG_COMPILER_APPICON_NAME "AppIcon")
set_xcode_property(${APP_NAME} DEVELOPMENT_TEAM "")
set_xcode_property(${APP_NAME} CODE_SIGN_IDENTITY "iPhone Developer")
Expand Down
3 changes: 2 additions & 1 deletion Classes/AppsFlyer/AppsFlyerXApple.mm
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@

[[AppsFlyerLib shared] validateAndLogInAppPurchase:afPurchaseDetails extraEventValues:lParams completionHandler:^(AFSDKValidateAndLogResult * _Nullable result) {
// TODO: - add result to completionHandler
NSLog(@"[ValidateAndLog] Result: %@", result);
NSLog(@"[ValidateAndLog] Result: %@", result.error);
NSLog(@"[ValidateAndLog] Result: %@", result.errorData);
AFSDKXValidateAndLogStatus status = AFSDKXValidateAndLogResult::objcEnumToCppEnum(result.status);
cocos2d::ValueMap resultX = AppsFlyerXAppleHelper::nsDictionary2ValueMap(result.result);
cocos2d::ValueMap errorData = AppsFlyerXAppleHelper::nsDictionary2ValueMap(result.errorData);
Expand Down
Loading
Loading