init
This commit is contained in:
47
Classes/JniCross/JniCallback.cpp
Normal file
47
Classes/JniCross/JniCallback.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "cocos2d.h"
|
||||
#include "JniCallback.h"
|
||||
#include "MissionWeiXin.h"
|
||||
#include "GlobalUserInfo.h"
|
||||
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||
#include <Jni.h>
|
||||
#include "android/jni/JniHelper.h"
|
||||
#endif
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
namespace JniFun
|
||||
{
|
||||
extern "C"
|
||||
{
|
||||
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_jxkh_queyi_Native_WxLoginGetAccessToken (JNIEnv* env, jclass method, jstring param)
|
||||
{
|
||||
const char* data = env->GetStringUTFChars(param, 0);
|
||||
cocos2d::log("JinCallBack :%s",data);
|
||||
MissionWeiXin::Instance().Req_Access_token(data);
|
||||
env->ReleaseStringUTFChars(param, data);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_jxkh_queyi_Native_WxLoginGetFailToken (JNIEnv* env, jclass method, jstring param)
|
||||
{
|
||||
const char* data = env->GetStringUTFChars(param, 0);
|
||||
cocos2d::log("JinCallBack :%s",data);
|
||||
MissionWeiXin::Instance().Req_Fail_token(data);
|
||||
env->ReleaseStringUTFChars(param, data);
|
||||
}
|
||||
|
||||
//java µ÷ÓÃ
|
||||
JNIEXPORT void JNICALL Java_com_jxkh_queyi_Native_onLocationChanged(JNIEnv* env, jclass method, jstring param)
|
||||
{
|
||||
const char* data = env->GetStringUTFChars(param, 0);
|
||||
cocos2d::log("JinCallBack :%s",data);
|
||||
CGlobalUserInfo::GetInstance()->onLocationChanaged(data);
|
||||
env->ReleaseStringUTFChars(param, data);
|
||||
} // Java_com_jxkh_wnmj_Native_onLocationChanged
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
7
Classes/JniCross/JniCallback.h
Normal file
7
Classes/JniCross/JniCallback.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
namespace JniFun
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
421
Classes/JniCross/JniFun.cpp
Normal file
421
Classes/JniCross/JniFun.cpp
Normal file
@@ -0,0 +1,421 @@
|
||||
#include "cocos2d.h"
|
||||
#include "JniFun.h"
|
||||
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||
#include <Jni.h>
|
||||
#include "android/jni/JniHelper.h"
|
||||
#endif
|
||||
|
||||
#define JAVA_CLASSNAME "com/jxkh/queyi/Native"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
namespace JniFun
|
||||
{
|
||||
|
||||
void longinWX(const char* APP_ID,const char* AppSecret)
|
||||
{
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||
JniMethodInfo minfo;
|
||||
bool isHave = JniHelper::getStaticMethodInfo(minfo,JAVA_CLASSNAME,"LoginWX","(Ljava/lang/String;Ljava/lang/String;)V");
|
||||
if (isHave)
|
||||
{
|
||||
jstring jAPP_ID = minfo.env->NewStringUTF(APP_ID);
|
||||
jstring jAppSecret = minfo.env->NewStringUTF(AppSecret);
|
||||
minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID,jAPP_ID,jAppSecret);
|
||||
|
||||
minfo.env->DeleteLocalRef(jAPP_ID);
|
||||
minfo.env->DeleteLocalRef(jAppSecret);
|
||||
minfo.env->DeleteLocalRef(minfo.classID);
|
||||
cocos2d::log("JniFun call LoginWX over!");
|
||||
}
|
||||
else
|
||||
{
|
||||
cocos2d::log("JniFun call LoginWX error!");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void shareImageWX(const char* ImgPath,int nType)
|
||||
{
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||
JniMethodInfo minfo;
|
||||
bool isHave = JniHelper::getStaticMethodInfo(minfo,JAVA_CLASSNAME,"ShareImageWX","(Ljava/lang/String;I)V");
|
||||
if (isHave)
|
||||
{
|
||||
jstring jImgPath = minfo.env->NewStringUTF(ImgPath);
|
||||
minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID,jImgPath,nType);
|
||||
cocos2d::log("JniFun call ShareImageWX over!");
|
||||
|
||||
minfo.env->DeleteLocalRef(jImgPath);
|
||||
minfo.env->DeleteLocalRef(minfo.classID);
|
||||
}
|
||||
else
|
||||
{
|
||||
cocos2d::log("JniFun call ShareImageWX error!");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void shareTextWX(const char* kText,int nType)
|
||||
{
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||
JniMethodInfo minfo;
|
||||
bool isHave = JniHelper::getStaticMethodInfo(minfo,JAVA_CLASSNAME,"ShareTextWX","(Ljava/lang/String;I)V");
|
||||
if (isHave)
|
||||
{
|
||||
jstring jkText = minfo.env->NewStringUTF(kText);
|
||||
minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID,jkText,nType);
|
||||
cocos2d::log("JniFun call ShareTextWX over!");
|
||||
|
||||
minfo.env->DeleteLocalRef(jkText);
|
||||
minfo.env->DeleteLocalRef(minfo.classID);
|
||||
}
|
||||
else
|
||||
{
|
||||
cocos2d::log("JniFun call ShareTextWX error!");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void shareUrlWX(const char* kUrl,const char* kTitle,const char* kDesc,int nType)
|
||||
{
|
||||
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||
JniMethodInfo minfo;
|
||||
bool isHave = JniHelper::getStaticMethodInfo(minfo,JAVA_CLASSNAME,"ShareUrlWX","(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V");
|
||||
if (isHave)
|
||||
{
|
||||
jstring jkUrlt = minfo.env->NewStringUTF(kUrl);
|
||||
jstring jkTitle = minfo.env->NewStringUTF(kTitle);
|
||||
jstring jkDesc = minfo.env->NewStringUTF(kDesc);
|
||||
minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID,jkUrlt,jkTitle,jkDesc,nType);
|
||||
cocos2d::log("JniFun call ShareUrlWX over!");
|
||||
|
||||
minfo.env->DeleteLocalRef(jkUrlt);
|
||||
minfo.env->DeleteLocalRef(jkTitle);
|
||||
minfo.env->DeleteLocalRef(jkDesc);
|
||||
minfo.env->DeleteLocalRef(minfo.classID);
|
||||
}
|
||||
else
|
||||
{
|
||||
cocos2d::log("JniFun call ShareUrlWX error!");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void shareImageXL(const char* ImgPath, int nType)
|
||||
{
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||
JniMethodInfo minfo;
|
||||
bool isHave = JniHelper::getStaticMethodInfo(minfo,JAVA_CLASSNAME,"ShareImageXL","(Ljava/lang/String;I)V");
|
||||
if (isHave)
|
||||
{
|
||||
jstring jImgPath = minfo.env->NewStringUTF(ImgPath);
|
||||
minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID,jImgPath,nType);
|
||||
cocos2d::log("JniFun call ShareImageXL over!");
|
||||
|
||||
minfo.env->DeleteLocalRef(jImgPath);
|
||||
minfo.env->DeleteLocalRef(minfo.classID);
|
||||
}
|
||||
else
|
||||
{
|
||||
cocos2d::log("JniFun call ShareImageXL error!");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void shareTextXL(const char* kText, int nType)
|
||||
{
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||
JniMethodInfo minfo;
|
||||
bool isHave = JniHelper::getStaticMethodInfo(minfo, JAVA_CLASSNAME, "ShareTextXL", "(Ljava/lang/String;I)V");
|
||||
if (isHave)
|
||||
{
|
||||
jstring jkText = minfo.env->NewStringUTF(kText);
|
||||
minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID, jkText, nType);
|
||||
cocos2d::log("JniFun call ShareTextXL over!");
|
||||
|
||||
minfo.env->DeleteLocalRef(jkText);
|
||||
minfo.env->DeleteLocalRef(minfo.classID);
|
||||
}
|
||||
else
|
||||
{
|
||||
cocos2d::log("JniFun call ShareTextXL error!");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void shareUrlXL(const char* kUrl, const char* kTitle, const char* kDesc, int nType)
|
||||
{
|
||||
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||
JniMethodInfo minfo;
|
||||
bool isHave = JniHelper::getStaticMethodInfo(minfo, JAVA_CLASSNAME, "ShareUrlXL", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V");
|
||||
if (isHave)
|
||||
{
|
||||
jstring jkUrlt = minfo.env->NewStringUTF(kUrl);
|
||||
jstring jkTitle = minfo.env->NewStringUTF(kTitle);
|
||||
jstring jkDesc = minfo.env->NewStringUTF(kDesc);
|
||||
minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID, jkUrlt, jkTitle, jkDesc, nType);
|
||||
cocos2d::log("JniFun call ShareUrlXL over!");
|
||||
|
||||
minfo.env->DeleteLocalRef(jkUrlt);
|
||||
minfo.env->DeleteLocalRef(jkTitle);
|
||||
minfo.env->DeleteLocalRef(jkDesc);
|
||||
minfo.env->DeleteLocalRef(minfo.classID);
|
||||
}
|
||||
else
|
||||
{
|
||||
cocos2d::log("JniFun call ShareUrlXL error!");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void showWebView(const char* url )
|
||||
{
|
||||
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||
JniMethodInfo minfo;
|
||||
bool isHave = JniHelper::getStaticMethodInfo(minfo,JAVA_CLASSNAME,"showWebView","(Ljava/lang/String;)V");
|
||||
if (isHave)
|
||||
{
|
||||
jstring jurl = minfo.env->NewStringUTF(url);
|
||||
minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID,jurl);
|
||||
cocos2d::log("JniFun call showWebView over!");
|
||||
|
||||
minfo.env->DeleteLocalRef(jurl);
|
||||
minfo.env->DeleteLocalRef(minfo.classID);
|
||||
}
|
||||
else
|
||||
{
|
||||
cocos2d::log("JniFun call showWebView error!");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// 版本更新
|
||||
void versionUpdate(const char* url ,const char* desc, const int filesize, const int isUpdate)
|
||||
{
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||
JniMethodInfo minfo;
|
||||
bool isHave = JniHelper::getStaticMethodInfo(minfo,JAVA_CLASSNAME, "versionUpdate", "(Ljava/lang/String;Ljava/lang/String;II)V");
|
||||
if (isHave)
|
||||
{
|
||||
jstring jFileName = minfo.env->NewStringUTF(url);
|
||||
jstring jDes = minfo.env->NewStringUTF(desc);
|
||||
minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID,jFileName,jDes, filesize, isUpdate);
|
||||
|
||||
cocos2d::log("JniFun call versionUpdate over!");
|
||||
|
||||
minfo.env->DeleteLocalRef(jFileName);
|
||||
minfo.env->DeleteLocalRef(jDes);
|
||||
minfo.env->DeleteLocalRef(minfo.classID);
|
||||
}
|
||||
else
|
||||
{
|
||||
cocos2d::log("JniFun call versionUpdate error!");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static std::string kRecordFileName = "";
|
||||
void startSoundRecord()
|
||||
{
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||
JniMethodInfo minfo;
|
||||
bool isHave = JniHelper::getStaticMethodInfo(minfo,JAVA_CLASSNAME, "startSoundRecord", "()V");
|
||||
if (isHave)
|
||||
{
|
||||
minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID);
|
||||
cocos2d::log("JniFun call startSoundRecord over!");
|
||||
|
||||
minfo.env->DeleteLocalRef(minfo.classID);
|
||||
}
|
||||
else
|
||||
{
|
||||
cocos2d::log("JniFun call startSoundRecord error!");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
const char* stopSoundRecord()
|
||||
{
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
|
||||
std::string str;
|
||||
JniMethodInfo minfo;
|
||||
bool isHave = JniHelper::getStaticMethodInfo(minfo,JAVA_CLASSNAME, "stopSoundRecord", "()Ljava/lang/String;");
|
||||
if (isHave)
|
||||
{
|
||||
jstring jFileName = (jstring)minfo.env->CallStaticObjectMethod(minfo.classID, minfo.methodID);
|
||||
const char *newStr = minfo.env->GetStringUTFChars(jFileName, 0);
|
||||
str = newStr;
|
||||
cocos2d::log("JniFun call stopSoundRecord over :");
|
||||
cocos2d::log("%s",str.c_str());
|
||||
minfo.env->ReleaseStringUTFChars(jFileName, newStr);
|
||||
minfo.env->DeleteLocalRef(minfo.classID);
|
||||
}
|
||||
else
|
||||
{
|
||||
cocos2d::log("JniFun call stopSoundRecord error!");
|
||||
}
|
||||
return str.c_str();
|
||||
#endif
|
||||
return "";
|
||||
}
|
||||
|
||||
//获取版本号
|
||||
int getVersionCode(void)
|
||||
{
|
||||
int nVerCode = 0;
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
nVerCode = 100;
|
||||
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
JniMethodInfo minfo;
|
||||
if (JniHelper::getStaticMethodInfo(minfo, JAVA_CLASSNAME, "getVersionCode", "()I"))
|
||||
{
|
||||
nVerCode = minfo.env->CallStaticIntMethod(minfo.classID, minfo.methodID);
|
||||
minfo.env->DeleteLocalRef(minfo.classID);
|
||||
}
|
||||
#endif
|
||||
return nVerCode;
|
||||
}
|
||||
|
||||
//获取版本号
|
||||
std::string getVersionName(void)
|
||||
{
|
||||
std::string strVerName;
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
strVerName = "1.0.8";
|
||||
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
JniMethodInfo minfo;
|
||||
if (JniHelper::getStaticMethodInfo(minfo, JAVA_CLASSNAME, "getVersionName", "()Ljava/lang/String;"))
|
||||
{
|
||||
jstring ret = (jstring)minfo.env->CallStaticObjectMethod(minfo.classID, minfo.methodID);
|
||||
strVerName = JniHelper::jstring2string(ret);
|
||||
minfo.env->DeleteLocalRef(ret);
|
||||
minfo.env->DeleteLocalRef(minfo.classID);
|
||||
}
|
||||
#endif
|
||||
return strVerName;
|
||||
}
|
||||
|
||||
//获取应用名称
|
||||
std::string getAppName(void)
|
||||
{
|
||||
std::string strAppName;
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
strAppName = "wnmj";
|
||||
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
JniMethodInfo minfo;
|
||||
if (JniHelper::getStaticMethodInfo(minfo, JAVA_CLASSNAME, "getAppName", "()Ljava/lang/String;"))
|
||||
{
|
||||
jstring ret = (jstring)minfo.env->CallStaticObjectMethod(minfo.classID, minfo.methodID);
|
||||
strAppName = JniHelper::jstring2string(ret);
|
||||
minfo.env->DeleteLocalRef(ret);
|
||||
minfo.env->DeleteLocalRef(minfo.classID);
|
||||
}
|
||||
#endif
|
||||
return strAppName;
|
||||
}
|
||||
|
||||
//获取APP启动参数
|
||||
std::string getRunParam(void)
|
||||
{
|
||||
std::string strRunAppParam;
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
JniMethodInfo minfo;
|
||||
if (JniHelper::getStaticMethodInfo(minfo, JAVA_CLASSNAME, "getRunParam", "()Ljava/lang/String;"))
|
||||
{
|
||||
jstring ret = (jstring)minfo.env->CallStaticObjectMethod(minfo.classID, minfo.methodID);
|
||||
strRunAppParam = JniHelper::jstring2string(ret);
|
||||
minfo.env->DeleteLocalRef(ret);
|
||||
minfo.env->DeleteLocalRef(minfo.classID);
|
||||
}
|
||||
#endif
|
||||
return strRunAppParam;
|
||||
}
|
||||
|
||||
//打开链接
|
||||
void openURL(const std::string &url)
|
||||
{
|
||||
showWebView(url.c_str());
|
||||
}
|
||||
|
||||
std::string getSystemTime()
|
||||
{
|
||||
time_t t = time(NULL);
|
||||
struct tm* tt = localtime(&t);
|
||||
char timeString[16] = { 0 };
|
||||
sprintf(timeString, "%02d:%02d", tt->tm_hour, tt->tm_min);
|
||||
return std::string(timeString);
|
||||
}
|
||||
|
||||
std::string getDataTime()
|
||||
{
|
||||
time_t t = time(NULL);
|
||||
struct tm* tt = localtime(&t);
|
||||
char timeString[32] = { 0 };
|
||||
sprintf(timeString, "%04d-%02d-%02d %02d:%02d", tt->tm_year+1900, tt->tm_mon+1, tt->tm_mday, tt->tm_hour, tt->tm_min);
|
||||
return std::string(timeString);
|
||||
}
|
||||
|
||||
long long getCurrTime()
|
||||
{
|
||||
//return time(NULL);
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, nullptr);
|
||||
long long ms = tv.tv_sec;
|
||||
return ms * 1000 + tv.tv_usec / 1000;
|
||||
}
|
||||
|
||||
void startLocation()
|
||||
{
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
JniMethodInfo minfo;
|
||||
bool isHave = JniHelper::getStaticMethodInfo(minfo, JAVA_CLASSNAME, "startLocation", "()V");
|
||||
if (isHave)
|
||||
{
|
||||
minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID);
|
||||
cocos2d::log("JniFun call startLocation over!");
|
||||
minfo.env->DeleteLocalRef(minfo.classID);
|
||||
}
|
||||
else
|
||||
{
|
||||
cocos2d::log("JniFun call startLocation error!");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void stopLocation()
|
||||
{
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
JniMethodInfo minfo;
|
||||
bool isHave = JniHelper::getStaticMethodInfo(minfo, JAVA_CLASSNAME, "stopLocation", "()V");
|
||||
if (isHave)
|
||||
{
|
||||
minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID);
|
||||
cocos2d::log("JniFun call stopLocation over!");
|
||||
minfo.env->DeleteLocalRef(minfo.classID);
|
||||
}
|
||||
else
|
||||
{
|
||||
cocos2d::log("JniFun call stopLocation error!");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
double distanceBetween(double aLatitude, double aLongitude, double bLatitude, double bLongitude)
|
||||
{
|
||||
double dDistance = 0.f;
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
JniMethodInfo minfo;
|
||||
if (JniHelper::getStaticMethodInfo(minfo, JAVA_CLASSNAME, "distanceBetween", "(DDDD)D"))
|
||||
{
|
||||
dDistance = minfo.env->CallStaticIntMethod(minfo.classID, minfo.methodID, aLatitude, aLongitude, bLatitude, bLongitude);
|
||||
minfo.env->DeleteLocalRef(minfo.classID);
|
||||
}
|
||||
#endif
|
||||
return dDistance;
|
||||
}
|
||||
}
|
||||
48
Classes/JniCross/JniFun.h
Normal file
48
Classes/JniCross/JniFun.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
namespace JniFun
|
||||
{
|
||||
void longinWX(const char* APP_ID,const char* AppSecret);
|
||||
void shareImageWX(const char* ImgPath,int nType);
|
||||
void shareTextWX(const char* kText,int nType);
|
||||
void shareUrlWX(const char* kUrl,const char* kTitle,const char* kDesc,int nType);
|
||||
|
||||
void shareImageXL(const char* ImgPath, int nType);
|
||||
void shareTextXL(const char* kText, int nType);
|
||||
void shareUrlXL(const char* kUrl, const char* kTitle, const char* kDesc, int nType);
|
||||
|
||||
void showWebView(const char* url );
|
||||
void versionUpdate(const char* url ,const char* desc, const int filesize, const int isUpdate);
|
||||
|
||||
void startSoundRecord();
|
||||
const char* stopSoundRecord();
|
||||
|
||||
//获取版本号
|
||||
int getVersionCode(void);
|
||||
//获取版本号
|
||||
std::string getVersionName(void);
|
||||
//获取应用名称
|
||||
std::string getAppName(void);
|
||||
|
||||
//获取APP启动参数
|
||||
std::string getRunParam(void);
|
||||
|
||||
//打开链接
|
||||
void openURL(const std::string &url);
|
||||
|
||||
//获取系统时间
|
||||
std::string getSystemTime();
|
||||
|
||||
std::string getDataTime();
|
||||
|
||||
//获取系统时间(毫秒)
|
||||
long long getCurrTime();
|
||||
|
||||
void startLocation();
|
||||
|
||||
void stopLocation();
|
||||
|
||||
double distanceBetween(double aLatitude, double aLongitude, double bLatitude, double bLongitude);
|
||||
}
|
||||
|
||||
186
Classes/JniCross/JniFun.mm
Normal file
186
Classes/JniCross/JniFun.mm
Normal file
@@ -0,0 +1,186 @@
|
||||
#include "cocos2d.h"
|
||||
#include "JniFun.h"
|
||||
|
||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_IOS
|
||||
#include "IosHelper.h"
|
||||
#import <TencentLBS/TencentLBSLocationUtils.h>
|
||||
USING_NS_CC;
|
||||
|
||||
namespace JniFun
|
||||
{
|
||||
void longinWX(const char* APP_ID,const char* AppSecret)
|
||||
{
|
||||
IosHelper::sendWxAuthRequest();
|
||||
}
|
||||
|
||||
void shareImageWX(const char* ImgPath,int nType)
|
||||
{
|
||||
if (nType == 0)
|
||||
{
|
||||
IosHelper::shareWithWeixinFriendImg("",ImgPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
IosHelper::shareWithWeixinCircleImg("",ImgPath);
|
||||
}
|
||||
}
|
||||
|
||||
void shareTextWX(const char* kText,int nType)
|
||||
{
|
||||
if (nType == 0)
|
||||
{
|
||||
IosHelper::shareWithWeixinFriendTxt(kText);
|
||||
}
|
||||
else
|
||||
{
|
||||
IosHelper::shareWithWeixinCircleTxt(kText);
|
||||
}
|
||||
}
|
||||
|
||||
void shareUrlWX(const char* kUrl,const char* kTitle,const char* kDesc,int nType)
|
||||
{
|
||||
if (nType == 0)
|
||||
{
|
||||
IosHelper::shareWithWeixinFriendUrl(kTitle,kDesc,kUrl);
|
||||
}
|
||||
else
|
||||
{
|
||||
IosHelper::shareWithWeixinCircleUrl(kTitle,kDesc,kUrl);
|
||||
}
|
||||
}
|
||||
|
||||
// xianliao
|
||||
void shareImageXL(const char* ImgPath, int nType)
|
||||
{
|
||||
IosHelper::shareWithXLFriendImg("",ImgPath);
|
||||
}
|
||||
|
||||
void shareTextXL(const char* kText, int nType)
|
||||
{
|
||||
IosHelper::shareWithXLFriendTxt(kText);
|
||||
}
|
||||
|
||||
void shareUrlXL(const char* kUrl, const char* kTitle, const char* kDesc, int nType)
|
||||
{
|
||||
IosHelper::shareWithXLFriendUrl(kTitle,kDesc,kUrl);
|
||||
}
|
||||
|
||||
void showWebView(const char* url )
|
||||
{
|
||||
IosHelper::startBrowserJni(url);
|
||||
}
|
||||
|
||||
// 版本更新
|
||||
void versionUpdate(const char* url ,const char* desc, const int filesize, const int isUpdate)
|
||||
{
|
||||
//IosHelper::startBrowserJni(url);
|
||||
}
|
||||
|
||||
static std::string kRecordFileName = "";
|
||||
void startSoundRecord()
|
||||
{
|
||||
kRecordFileName = cocos2d::FileUtils::getInstance()->getWritablePath()+"SoundRecord.wav";
|
||||
IosHelper::beginRecord(kRecordFileName.c_str());
|
||||
}
|
||||
|
||||
const char* stopSoundRecord()
|
||||
{
|
||||
IosHelper::endRecord();
|
||||
return kRecordFileName.c_str();
|
||||
}
|
||||
|
||||
// 将NSString类型转化为string类型
|
||||
std::string NSString2String(NSString* str)
|
||||
{
|
||||
const char* cstr = [str cStringUsingEncoding : NSUTF8StringEncoding];
|
||||
return std::string(cstr);
|
||||
}
|
||||
|
||||
//获取版本号
|
||||
int getVersionCode(void)
|
||||
{
|
||||
int nVerCode = 0;
|
||||
NSString* appBundleVer = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
|
||||
const char* cstr = [appBundleVer cStringUsingEncoding : NSUTF8StringEncoding];
|
||||
nVerCode = atoi(cstr);
|
||||
return nVerCode;
|
||||
}
|
||||
|
||||
//获取版本号
|
||||
std::string getVersionName(void)
|
||||
{
|
||||
std::string strVerName;
|
||||
NSString* appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
|
||||
strVerName = NSString2String(appVersion);
|
||||
return strVerName;
|
||||
}
|
||||
|
||||
//获取应用名称
|
||||
std::string getAppName(void)
|
||||
{
|
||||
std::string strAppName;
|
||||
NSString* appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];
|
||||
strAppName = NSString2String(appName);
|
||||
return strAppName;
|
||||
}
|
||||
|
||||
//获取APP启动参数
|
||||
std::string getRunParam(void)
|
||||
{
|
||||
std::string strRunParam;
|
||||
|
||||
return strRunParam;
|
||||
}
|
||||
|
||||
void openURL(const std::string &url)
|
||||
{
|
||||
NSString* str = [NSString stringWithCString:url.c_str() encoding:NSUTF8StringEncoding];
|
||||
NSURL* URL = [NSURL URLWithString:str];
|
||||
[[UIApplication sharedApplication] openURL:URL];
|
||||
}
|
||||
|
||||
std::string getSystemTime()
|
||||
{
|
||||
time_t t = time(NULL);
|
||||
struct tm* tt = localtime(&t);
|
||||
char timeString[16] = {0};
|
||||
sprintf(timeString, "%02d:%02d", tt->tm_hour, tt->tm_min);
|
||||
return std::string(timeString);
|
||||
}
|
||||
|
||||
std::string getDataTime()
|
||||
{
|
||||
time_t t = time(NULL);
|
||||
struct tm* tt = localtime(&t);
|
||||
char timeString[32] = { 0 };
|
||||
sprintf(timeString, "%04d-%02d-%02d %02d:%02d", tt->tm_year+1900, tt->tm_mon+1, tt->tm_mday, tt->tm_hour, tt->tm_min);
|
||||
return std::string(timeString);
|
||||
}
|
||||
|
||||
long long getCurrTime()
|
||||
{
|
||||
NSTimeInterval nowtime = [[NSDate date] timeIntervalSince1970]*1000;
|
||||
long long theTime = [[NSNumber numberWithDouble:nowtime] longLongValue];
|
||||
return theTime;
|
||||
}
|
||||
|
||||
void startLocation()
|
||||
{
|
||||
[IosHelper::locationManager startUpdatingLocation];
|
||||
}
|
||||
|
||||
void stopLocation()
|
||||
{
|
||||
[IosHelper::locationManager stopUpdatingLocation];
|
||||
}
|
||||
|
||||
double distanceBetween(double aLatitude, double aLongitude, double bLatitude, double bLongitude)
|
||||
{
|
||||
CLLocation *l1 = [[CLLocation alloc] initWithLatitude:aLatitude longitude:aLongitude];
|
||||
CLLocation *l2 = [[CLLocation alloc] initWithLatitude:bLatitude longitude:bLongitude];
|
||||
|
||||
return [TencentLBSLocationUtils distanceBetweenTwoCLLocations:l1 locationTwo:l2];
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user