Commit 6c44ef6c authored by fengchao's avatar fengchao
Browse files

fix(code):upcode_ios

parent c141e353
...@@ -7,22 +7,26 @@ ...@@ -7,22 +7,26 @@
@end @end
extern "C" { extern "C" {
// JSON工具函数:支持 NSDictionary 和 NSArray
// JSON工具函数 NSString* jsonStringWithObject(id obj) {
NSString* jsonStringWithDictionary(NSDictionary* dict) { if (!obj) return @"{}";
if (!dict) return @"{}"; if (![NSJSONSerialization isValidJSONObject:obj]) {
NSLog(@"⚠️ 无法序列化对象:%@", obj);
return @"{}";
}
NSError *error; NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:&error]; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:obj options:0 error:&error];
if (jsonData) { if (jsonData) {
return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
} else {
NSLog(@"❌ JSON 转换失败:%@", error.localizedDescription);
return @"{}";
} }
return @"{}";
} }
void UnitySendMessage(const char*, const char*, const char*); void UnitySendMessage(const char*, const char*, const char*);
} }
@implementation SDKDelegate @implementation SDKDelegate
#pragma mark - HLSystemDelegate #pragma mark - HLSystemDelegate
...@@ -33,7 +37,7 @@ extern "C" { ...@@ -33,7 +37,7 @@ extern "C" {
@"gameId": @(initResult.gameId), @"gameId": @(initResult.gameId),
@"channelId": @(initResult.channelId) @"channelId": @(initResult.channelId)
}; };
NSString *json = jsonStringWithDictionary(dict); NSString *json = jsonStringWithObject(dict);
UnitySendMessage("SdkManager", "OnSdkInit", [json UTF8String]); UnitySendMessage("SdkManager", "OnSdkInit", [json UTF8String]);
} }
...@@ -71,11 +75,7 @@ extern "C" { ...@@ -71,11 +75,7 @@ extern "C" {
}; };
[array addObject:dict]; [array addObject:dict];
} }
NSString *json = jsonStringWithObject(array);
// 包一层,方便 Unity JsonUtility 解析
NSDictionary *wrapper = @{@"array": array};
NSString *json = jsonStringWithDictionary(wrapper);
UnitySendMessage("SdkManager", "OnPayGoodsList", [json UTF8String]); UnitySendMessage("SdkManager", "OnPayGoodsList", [json UTF8String]);
} }
...@@ -95,7 +95,7 @@ extern "C" { ...@@ -95,7 +95,7 @@ extern "C" {
@"serverArea": accountInfo.serverArea ?: @"", @"serverArea": accountInfo.serverArea ?: @"",
@"extendInfo": accountInfo.extendInfo ?: @{} @"extendInfo": accountInfo.extendInfo ?: @{}
}; };
NSString *json = jsonStringWithDictionary(dict); NSString *json = jsonStringWithObject(dict);
UnitySendMessage("SdkManager", "OnLoginSuccess", [json UTF8String]); UnitySendMessage("SdkManager", "OnLoginSuccess", [json UTF8String]);
} }
...@@ -109,7 +109,7 @@ extern "C" { ...@@ -109,7 +109,7 @@ extern "C" {
@"serverArea": refreshAccountInfo.serverArea ?: @"", @"serverArea": refreshAccountInfo.serverArea ?: @"",
@"extendInfo": refreshAccountInfo.extendInfo ?: @{} @"extendInfo": refreshAccountInfo.extendInfo ?: @{}
}; };
NSString *json = jsonStringWithDictionary(dict); NSString *json = jsonStringWithObject(dict);
UnitySendMessage("SdkManager", "OnUserRefresh", [json UTF8String]); UnitySendMessage("SdkManager", "OnUserRefresh", [json UTF8String]);
} }
......
#if UNITY_IOS && !UNITY_EDITOR #if UNITY_IOS
using UnityEngine; using UnityEngine;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System; using System;
......
...@@ -61,7 +61,7 @@ PlayerSettings: ...@@ -61,7 +61,7 @@ PlayerSettings:
allowedAutorotateToPortrait: 0 allowedAutorotateToPortrait: 0
allowedAutorotateToPortraitUpsideDown: 0 allowedAutorotateToPortraitUpsideDown: 0
allowedAutorotateToLandscapeRight: 1 allowedAutorotateToLandscapeRight: 1
allowedAutorotateToLandscapeLeft: 0 allowedAutorotateToLandscapeLeft: 1
useOSAutorotation: 1 useOSAutorotation: 1
use32BitDisplayBuffer: 1 use32BitDisplayBuffer: 1
preserveFramebufferAlpha: 0 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