Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
sdk-public
unity_sdk_demo
Commits
6c44ef6c
Commit
6c44ef6c
authored
Oct 15, 2025
by
fengchao
Browse files
fix(code):upcode_ios
parent
c141e353
Changes
3
Hide whitespace changes
Inline
Side-by-side
Assets/Plugins/iOS/UnityBridge.mm
View file @
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
@"{}"
;
}
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
=
jsonStringWith
Dictionary
(
dict
);
NSString
*
json
=
jsonStringWith
Object
(
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
=
jsonStringWith
Dictionary
(
dict
);
NSString
*
json
=
jsonStringWith
Object
(
dict
);
UnitySendMessage
(
"SdkManager"
,
"OnLoginSuccess"
,
[
json
UTF8String
]);
}
...
...
@@ -109,7 +109,7 @@ extern "C" {
@"serverArea"
:
refreshAccountInfo
.
serverArea
?:
@""
,
@"extendInfo"
:
refreshAccountInfo
.
extendInfo
?:
@{}
};
NSString
*
json
=
jsonStringWith
Dictionary
(
dict
);
NSString
*
json
=
jsonStringWith
Object
(
dict
);
UnitySendMessage
(
"SdkManager"
,
"OnUserRefresh"
,
[
json
UTF8String
]);
}
...
...
Assets/Scripts/sdk/channel/IosSdkInterface.cs
View file @
6c44ef6c
#if UNITY_IOS
&& !UNITY_EDITOR
#if UNITY_IOS
using
UnityEngine
;
using
System.Runtime.InteropServices
;
using
System
;
...
...
ProjectSettings/ProjectSettings.asset
View file @
6c44ef6c
...
...
@@ -61,7 +61,7 @@ PlayerSettings:
allowedAutorotateToPortrait
:
0
allowedAutorotateToPortraitUpsideDown
:
0
allowedAutorotateToLandscapeRight
:
1
allowedAutorotateToLandscapeLeft
:
0
allowedAutorotateToLandscapeLeft
:
1
useOSAutorotation
:
1
use32BitDisplayBuffer
:
1
preserveFramebufferAlpha
:
0
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment