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 “”;

}

猜你喜欢

转载自blog.csdn.net/qq_21743659/article/details/108529022