enhance ChangeLinkAccount functionality
- Added LoginTypeToBindType function to map login types to binding types. - Updated ChangeLinkAccount method to handle account linking and unbinding with appropriate error handling. - Ensured proper messaging for success and failure cases during account changes. - Cleaned temporary SNS information after account change attempts.
This commit is contained in:
@@ -147,6 +147,20 @@ extern "C" {
|
||||
}
|
||||
}
|
||||
|
||||
NSInteger LoginTypeToBindType(NSInteger loginType)
|
||||
{
|
||||
switch (loginType) {
|
||||
case XYLoginWithApple:
|
||||
return XYBindApple;
|
||||
case XYLoginWithFB:
|
||||
return XYBindFB;
|
||||
case XYLoginWithGoogle:
|
||||
return XYBindGoodle;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
const char* UnityLoginBySnsInfo()
|
||||
{
|
||||
NSLog(@"TYSdkInterface UnityLoginBySnsInfo");
|
||||
@@ -387,10 +401,6 @@ extern "C" {
|
||||
}];
|
||||
}
|
||||
|
||||
void UnlinkGoogle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void LinkFacebook(const int userId)
|
||||
{
|
||||
@@ -412,10 +422,6 @@ extern "C" {
|
||||
}];
|
||||
}
|
||||
|
||||
void UnlinkFacebook()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void LinkApple(const int userId)
|
||||
{
|
||||
@@ -437,11 +443,60 @@ extern "C" {
|
||||
}];
|
||||
}
|
||||
|
||||
void UnlinkApple()
|
||||
void ChangeLinkAccount(const int accoutType, const int oldUserId, const int newUserId)
|
||||
{
|
||||
NSLog(@"TYSdkInterface ChangeLinkAccount accoutType:%d oldUserId:%d newUserId:%d", accoutType, oldUserId, newUserId);
|
||||
|
||||
if (g_snsLoginType == -1)
|
||||
{
|
||||
UnitySendMessage("TYSdkFacade", "ChangeLinkAccountResult",
|
||||
"{\"code\":1, \"userId\": 0, \"msg\": \"g_snsLoginType is invalid\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
NSInteger bindTypeValue = LoginTypeToBindType(g_snsLoginType);
|
||||
if (bindTypeValue == -1)
|
||||
{
|
||||
UnitySendMessage("TYSdkFacade", "ChangeLinkAccountResult",
|
||||
"{\"code\":1, \"userId\": 0, \"msg\": \"unsupported account type\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
XYBindType bindType = (XYBindType)bindTypeValue;
|
||||
|
||||
XYBindReq *unbindReq = [XYBindReq initUnBindWithPlatform:bindType UserId:(NSUInteger)oldUserId];
|
||||
[XYApi XYUnBindByBindReq:unbindReq completionHandler:^(XYResp * _Nonnull unbindResp) {
|
||||
NSLog(@"TYSdkInterface ChangeLinkAccount unbind code:%ld msg:%@", (long)unbindResp.errCode, unbindResp.errStr);
|
||||
|
||||
if (unbindResp.errCode == XYSuccess)
|
||||
{
|
||||
XYBindReq *bindReq = [XYBindReq initBindWithPlatform:bindType UserId:(NSUInteger)newUserId];
|
||||
[XYApi XYBindByBindReq:bindReq isUnbindGuest:@"false" completionHandler:^(XYResp * _Nonnull bindResp) {
|
||||
NSLog(@"TYSdkInterface ChangeLinkAccount bind code:%ld msg:%@", (long)bindResp.errCode, bindResp.errStr);
|
||||
|
||||
if (bindResp.errCode == XYSuccess)
|
||||
{
|
||||
NSString *msg = [NSString stringWithFormat:@"{\"code\":0, \"userId\": %d, \"msg\": \"success\"}", newUserId];
|
||||
UnitySendMessage("TYSdkFacade", "ChangeLinkAccountResult", AllocCString(msg));
|
||||
}
|
||||
else
|
||||
{
|
||||
NSString *errStr = bindResp.errStr ? bindResp.errStr : @"bind failed";
|
||||
NSString *msg = [NSString stringWithFormat:@"{\"code\":-1, \"userId\": 0, \"msg\": \"%@\"}", errStr];
|
||||
UnitySendMessage("TYSdkFacade", "ChangeLinkAccountResult", AllocCString(msg));
|
||||
}
|
||||
}];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSString *errStr = unbindResp.errStr ? unbindResp.errStr : @"unbind failed";
|
||||
NSString *msg = [NSString stringWithFormat:@"{\"code\":1, \"userId\": 0, \"msg\": \"%@\"}", errStr];
|
||||
UnitySendMessage("TYSdkFacade", "ChangeLinkAccountResult", AllocCString(msg));
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
void FBShareLink(const char* title, const char* content, const char* url)
|
||||
{
|
||||
NSLog(@"TYSdkInterface FBShareLink");
|
||||
|
||||
Reference in New Issue
Block a user