-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathAdManager.cpp
More file actions
74 lines (62 loc) · 1.46 KB
/
Copy pathAdManager.cpp
File metadata and controls
74 lines (62 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// AdManager.cpp
// SnakeGameLua
//
// Created by Eleven Chen on 14-8-21.
//
//
#include "AdManager.h"
using namespace cocos2d;
using namespace std;
AdManager *g_adManager = nullptr;
AdManager* AdManager::getInstance()
{
if (g_adManager == nullptr)
{
g_adManager = new AdManager();
}
return g_adManager;
}
// Android平台
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
#include <jni.h>
#include "android/log.h"
#include "platform/android/jni/JniHelper.h"
#include <string>
const char* g_className = "org/cocos2dx/lua/AppActivity"; ///< 类名
void AdManager::showAds()
{
CCLOG("AdManager::showAds()");
JniMethodInfo minfo; // 定义Jni函数信息结构体
// 无参数
bool isHave = JniHelper::getStaticMethodInfo(minfo, g_className, "showAds", "()V");
if (!isHave) {
CCLog("jni: showAds 不存在");
} else {
minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID);
}
CCLog("jni-java 执行完毕");
}
void AdManager::hideAds()
{
CCLOG("AdManager::hideAds()");
JniMethodInfo minfo; // 定义Jni函数信息结构体
// 无参数
bool isHave = JniHelper::getStaticMethodInfo(minfo, g_className, "hideAds", "()V");
if (!isHave) {
CCLog("jni: hideAds 不存在");
} else {
minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID);
}
CCLog("jni-java 执行完毕");
}
#endif
// iOS平台
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
void AdManager::showAds()
{
}
void AdManager::hideAds()
{
}
#endif