187 lines
4.4 KiB
Plaintext
187 lines
4.4 KiB
Plaintext
#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
|