unity想跑IOS。必须拿真机测试。
错误总结
1. Permission denied的解决方法:chmod +x /Users/majiang/Desktop/U3DIOS/MapFileParser.sh
2. 必须将libWeChatSDK.a文件放到项目的Libraries文件夹下,然后在导入
3. 在unity的playerSetting中把auto graphics api的钩去除把metal删除
4. 如果爆不知名的错请把build settings 中的oc automatic这项选成YES
5. 把SendAuthReq中的autorelease去掉
extern "C"{
void WeiXinLoginByIos(){
NSLog(@"111");
//构造SendAuthReq结构体
SendAuthReq* req =[[SendAuthReq alloc ] init ];
req.scope = @"snsapi_userinfo" ;
req.state = @"123" ;
//第三方向微信终端发送一个SendAuthReq消息结构
[WXApi sendReq:req];
}
}
//重写微信方法(必要步骤)
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
return [WXApi handleOpenURL:url delegate:self];
}
//重写微信方法(必要步骤)
-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
return [WXApi handleOpenURL:url delegate:self];
}
-(void) onReq:(BaseReq *)req{}
#define WeiXinID @"你的APPID"
#define WeiXinSecret @"你的APPSecret"
#define GameObjectName "UI_Root"
#define MethodName "json_UserInfo"
-(void) onResp:(BaseResp *)resp{
if (resp.errCode==0) {
NSLog(@"微信登录返回成功!");
}else{
NSLog(@"微信登录失败! %d",resp.errCode);
}
/*
enum WXErrCode {
WXSuccess = 0, 成功
WXErrCodeCommon = -1, 普通错误类型
WXErrCodeUserCancel = -2, 用户点击取消并返回
WXErrCodeSentFail = -3, 发送失败
WXErrCodeAuthDeny = -4, 授权失败
WXErrCodeUnsupport = -5, 微信不支持
};
*/
// 返回成功,获取Code
SendAuthResp *sendResp = resp;
NSString *code = sendResp.code;
NSLog(@"code=%@",sendResp.code);
// 根据Code获取AccessToken(有限期2个小时)
// https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
//
// 发起GET请求
// 2.1.设置请求路径
NSString *urlStr = [NSString stringWithFormat:@"https://api.weixin.qq.com/sns/oauth2/access_token?appid=%@&secret=%@&code=%@&grant_type=authorization_code
",WeiXinID,WeiXinSecret,code];
// 转码
urlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
// URL里面不能包含中文
NSURL *url = [NSURL URLWithString:urlStr];
// 2.2.创建请求对象
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; // 默认就是GET请求
request.timeoutInterval = 5; // 设置请求超时
// 2.3.发送请求
[self sendAsync:request];
NSLog(@"---------已经发出请求");
}
//重写微信方法(必要步骤)
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
return [WXApi handleOpenURL:url delegate:self];
}
//重写微信方法(必要步骤)
-(BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options{
return [WXApi handleOpenURL:url delegate:self];
}
-(void) onReq:(BaseReq *)req{}
#define WeiXinID @"你的APPID"
#define WeiXinSecret @"你的APPSecret"
#define GameObjectName "UI_Root"
#define MethodName "json_UserInfo"
-(void) onResp:(BaseResp *)resp{
if (resp.errCode==0) {
NSLog(@"微信登录返回成功!");
}else{
NSLog(@"微信登录失败! %d",resp.errCode);
}
/*
enum WXErrCode {
WXSuccess = 0, 成功
WXErrCodeCommon = -1, 普通错误类型
WXErrCodeUserCancel = -2, 用户点击取消并返回
WXErrCodeSentFail = -3, 发送失败
WXErrCodeAuthDeny = -4, 授权失败
WXErrCodeUnsupport = -5, 微信不支持
};
*/
// 返回成功,获取Code
SendAuthResp *sendResp = resp;
NSString *code = sendResp.code;
NSLog(@"code=%@",sendResp.code);
// 根据Code获取AccessToken(有限期2个小时)
// https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
//
// 发起GET请求
// 2.1.设置请求路径
NSString *urlStr = [NSString stringWithFormat:@"https://api.weixin.qq.com/sns/oauth2/access_token?appid=%@&secret=%@&code=%@&grant_type=authorization_code
",WeiXinID,WeiXinSecret,code];
// 转码
urlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
// URL里面不能包含中文
NSURL *url = [NSURL URLWithString:urlStr];
// 2.2.创建请求对象
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; // 默认就是GET请求
request.timeoutInterval = 5; // 设置请求超时
// 2.3.发送请求
[self sendAsync:request];
NSLog(@"---------已经发出请求");
}