cocos2d-x调用java接口详解

cocos2d-x调用java接口

1. jni.h , F:\cocos2d-x-3.2\cocos\platform\android\jni\jni\JniHelper.h

2. 如果jni.h没有,去C:\Program Files\Java\jdk1.7.0_05\include\jni.h and C:\Program Files\Java\jdk1.7.0_05\include\win32\jni_md.h copy to VS setup path VC/include

3.

4.

get not static function

from gongsi

std::string PlatformTool::doAction(const std::string &json){

NSString* jsonString = [NSString stringWithUTF8String:json.c_str()];

BOOL match = ([jsonString rangeOfString:@”app_key” options:NSCaseInsensitiveSearch].location != NSNotFound);

if(match){

NSError *error = NULL;

NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@”\”app_key\”:\”.*?\”” options:NSRegularExpressionCaseInsensitive error:&error];

NSString *modifiedString = [regex stringByReplacingMatchesInString:jsonString

options:0

range:NSMakeRange(0, [jsonString length])

withTemplate:@”\”app_key\”:\”\””];

NSLog(@”PlatformTool::doAction %@”,modifiedString);

}else{

NSLog(@”PlatformTool::doAction %@”,jsonString);

}

id jsonObject = [[NSString stringWithUTF8String:json.c_str()] objectFromJSONString];

if ([jsonObject respondsToSelector:@selector(objectForKey:)]) {

NSString *action = [jsonObject objectForKey:@”action”];

if ([action isEqualToString:@”PlatformToolLogin”]) {

PlatformToolLoginDelegate *d = [[PlatformToolLoginDelegate alloc] init];

EGOTextFieldAlertView* alertView = [[EGOTextFieldAlertView alloc] initWithTitle:@”登录”

message:nil

delegate:d

cancelButtonTitle:@”取消”

otherButtonTitles:@”登录”,@”注册”,nil];

NSString* username = [jsonObject objectForKey:@”username”];

NSString* password = [jsonObject objectForKey:@”password”];

[alertView setKeyboardVisibleWhenShow:false];

[alertView addTextFieldWithLabel:@”邮箱” value: username];

[alertView addTextFieldWithLabel:@”密码” value: password];

[alertView textFieldForIndex:0].keyboardType = UIKeyboardTypeEmailAddress;

[alertView textFieldForIndex:0].autocapitalizationType = UITextAutocapitalizationTypeNone;

[alertView textFieldForIndex:0].autocorrectionType = UITextAutocorrectionTypeNo;

[alertView textFieldForIndex:1].secureTextEntry = YES;

[alertView textFieldForIndex:1].returnKeyType = UIReturnKeyDone;

[alertView textFieldForIndex:1].delegate = d;

[alertView show];

[alertView autorelease];

}else if ([action isEqualToString:@”PlatformToolRegister”]) {

PlatformToolRegisterDelegate *d = [[PlatformToolRegisterDelegate alloc] init];

EGOTextFieldAlertView* alertView = [[EGOTextFieldAlertView alloc] initWithTitle:@”注册”

message:nil

delegate:d

cancelButtonTitle:@”取消”

otherButtonTitles:@”注册”,nil];

[alertView setKeyboardVisibleWhenShow:false];

NSString* username = [jsonObject objectForKey:@”username”];

NSString* password1 = [jsonObject objectForKey:@”password1″];

NSString* password2 = [jsonObject objectForKey:@”password2″];

[alertView addTextFieldWithLabel:@”邮箱” value: username];

[alertView addTextFieldWithLabel:@”密码” value: password1];

[alertView addTextFieldWithLabel:@”确认密码” value: password2];

[alertView textFieldForIndex:0].keyboardType = UIKeyboardTypeEmailAddress;

[alertView textFieldForIndex:0].autocapitalizationType = UITextAutocapitalizationTypeNone;

[alertView textFieldForIndex:0].autocorrectionType = UITextAutocorrectionTypeNo;

[alertView textFieldForIndex:1].secureTextEntry = YES;

[alertView textFieldForIndex:2].secureTextEntry = YES;

[alertView textFieldForIndex:2].returnKeyType = UIReturnKeyDone;

[alertView textFieldForIndex:2].delegate = d;

[alertView show];

[alertView autorelease];

}

}

return “”;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值