Commit 3b5b3df0 authored by wushaojie's avatar wushaojie 🏀
Browse files

Merge branch 'feat-dev-ios' into 'main'

fix(code):upcode_ios

See merge request unity-cross/UnityDemo!5
parents c141e353 6c44ef6c
......@@ -7,22 +7,26 @@
@end
extern "C" {
// JSON工具函数
NSString* jsonStringWithDictionary(NSDictionary* dict) {
if (!dict) return @"{}";
// JSON工具函数:支持 NSDictionary 和 NSArray
NSString* jsonStringWithObject(id obj) {
if (!obj) return @"{}";
if (![NSJSONSerialization isValidJSONObject:obj]) {
NSLog(@"⚠️ 无法序列化对象:%@", obj);
return @"{}";
}
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:&error];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:obj options:0 error:&error];
if (jsonData) {
return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}
} else {
NSLog(@"❌ JSON 转换失败:%@", error.localizedDescription);
return @"{}";
}
}
void UnitySendMessage(const char*, const char*, const char*);
}
@implementation SDKDelegate
#pragma mark - HLSystemDelegate
......@@ -33,7 +37,7 @@ extern "C" {
@"gameId": @(initResult.gameId),
@"channelId": @(initResult.channelId)
};
NSString *json = jsonStringWithDictionary(dict);
NSString *json = jsonStringWithObject(dict);
UnitySendMessage("SdkManager", "OnSdkInit", [json UTF8String]);
}
......@@ -71,11 +75,7 @@ extern "C" {
};
[array addObject:dict];
}
// 包一层,方便 Unity JsonUtility 解析
NSDictionary *wrapper = @{@"array": array};
NSString *json = jsonStringWithDictionary(wrapper);
NSString *json = jsonStringWithObject(array);
UnitySendMessage("SdkManager", "OnPayGoodsList", [json UTF8String]);
}
......@@ -95,7 +95,7 @@ extern "C" {
@"serverArea": accountInfo.serverArea ?: @"",
@"extendInfo": accountInfo.extendInfo ?: @{}
};
NSString *json = jsonStringWithDictionary(dict);
NSString *json = jsonStringWithObject(dict);
UnitySendMessage("SdkManager", "OnLoginSuccess", [json UTF8String]);
}
......@@ -109,7 +109,7 @@ extern "C" {
@"serverArea": refreshAccountInfo.serverArea ?: @"",
@"extendInfo": refreshAccountInfo.extendInfo ?: @{}
};
NSString *json = jsonStringWithDictionary(dict);
NSString *json = jsonStringWithObject(dict);
UnitySendMessage("SdkManager", "OnUserRefresh", [json UTF8String]);
}
......
#if UNITY_IOS && !UNITY_EDITOR
#if UNITY_IOS
using UnityEngine;
using System.Runtime.InteropServices;
using System;
......
......@@ -61,7 +61,7 @@ PlayerSettings:
allowedAutorotateToPortrait: 0
allowedAutorotateToPortraitUpsideDown: 0
allowedAutorotateToLandscapeRight: 1
allowedAutorotateToLandscapeLeft: 0
allowedAutorotateToLandscapeLeft: 1
useOSAutorotation: 1
use32BitDisplayBuffer: 1
preserveFramebufferAlpha: 0
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment