跳轉至

Advanced

帶入 Facebook 朋友列表

getProviderFriendsList() 方法提供同一遊戲中用戶 Facebook 朋友的 PlayerID。那些未使用 Facebook 同步的玩家不在好友列表中,而之前同步的玩家則返回 -1 作為 PlayerID。

Warning

Facebook 修訂了政策,該政策解釋了 2018 年 5 月對平台 API 的基本訪問權限項目。從此以後,要使用 Facebook /user/friends API,您需要 user_friends 權限。
查看 Facebook 應用程式審核指南

API 參考: hive.AuthV4.getProviderFriendsList

using hive;    

    AuthV4.ProviderType providerType = AuthV4.ProviderType.FACEBOOK;    

    AuthV4.getProviderFriendsList (providerType, (ResultAPI result, AuthV4.ProviderType providerType, Dictionary<String, Int64> providerUserIdList) => {    
         if (!result.isSuccess()) {    
             return;    
         }    

         if (providerUserIdList != null) {    
             foreach (KeyValuePair<String, Int64> providerUserId in providerUserIdList ) {    
                 // providerUserId: providerUserId.Key    
                 // playerId: providerUserId.Value    
             }    
         }    
});
#include "HiveAuthV4.h"

EHiveProviderType TargetProviderType = EHiveProviderType::FACEBOOK;
FHiveAuthV4::GetProviderFriendsList(TargetProviderType,
                                                                        FHiveAuthV4OnGetProviderFriendsListDelegate::CreateLambda([this](const FHiveResultAPI& Result, const EHiveProviderType& ProviderType, const ProviderFriendsMap& ProviderUserIdList) {
        // (alias) using ProviderFriendsMap = TMap<FString, int64>;
        if (!Result.IsSuccess()) {
                return;
        }

        for (const auto& ProviderUserIdEntry : ProviderUserIdList) {
                // ProviderUserId: ProviderUserIdEntry.Key;
                // Player Id: ProviderUserIdEntry.Value;
        }

}));

API 參考: AuthV4::getProviderFriendsList

#include <HIVE_SDK_Plugin/HIVE_CPP.h>    
    using namespace std;    
    using namespace hive;    

    ProviderType providerType = ProviderType::FACEBOOK;    

    AuthV4::getProviderFriendsList (providerType, [=](ResultAPI const & result, ProviderType providerType, map<string,PlayerID> providerUserIdList) {    
         if (!result.isSuccess()) {    
             return;    
         }    

         if (providerUserIdList != null) {    
             for(auto i = providerUserIdList.begin() ; i != providerUserIdList.end(); i++)    
             {    
                 // providerUserId: ( i->first).c_str()    
                 // playerId: i->second    
             }    
         }    
});

API 參考: com.hive.AuthV4.getProviderFriendsList

import com.hive.AuthV4    
    import com.hive.ResultAPI    

    val providerType = AuthV4.ProviderType.FACEBOOK    

    AuthV4.getProviderFriendsList(providerType, object : AuthV4.AuthV4ProviderFriendsListener {    
         override fun onGetProviderFriendsList(result: ResultAPI, providerType: AuthV4.ProviderType, providerUserIdList: Map<String, Long>?) {    
             if (!result.isSuccess) {    
                 return    
             }    

             providerUserIdList?.forEach {    
                 // providerUserId: it.key    
                 // playerId: it.value    
             }    
         }    
})

API 參考: com.hive.AuthV4.getProviderFriendsList

import com.hive.AuthV4;    
    import com.hive.ResultAPI;    

    AuthV4.ProviderType type = AuthV4.ProviderType.FACEBOOK;    

    AuthV4.INSTANCE.getProviderFriendsList(type, (result, providerType, providerUserIdList) -> {    
         if (!result.isSuccess()) {    
             return;    
         }    

         if (providerUserIdList != null) {    
             for (Map.Entry<String, Long> entry : providerUserIdList.entrySet()) {    
                 // providerUserId: entry.getKey();    
                 // playerId: entry.getValue();    
             }    
         }    
});

API 參考: AuthV4Interface.getProviderFriendsList

import HIVEService    

    AuthV4Interface.getProviderFriendsList(.Facebook) { result, retProviderType, providerUserIdList in    
         if !result.isSuccess() {    
             return    
         }    

         if let providerUserIdList = providerUserIdList {    
             for (key in providerUserIdList.keys) {    
                 // providerUserId: key    
                 // playerId: providerUserIdList[key]    
             }    
         }    
}

API 參考: HIVEAuthV4:getProviderFriendsList

#import <HIVEService/HIVEService-Swift.h>    

    [HIVEAuthV4 getProviderFriendsList: HIVEProviderTypeFACEBOOK handler: ^(HIVEResultAPI *result, HIVEProviderType retProviderType, NSDictionary<NSString *,NSNumber *> *providerUserIdList) {    
         if (!result.isSuccess()) {    
             return;    
         }    

         if (providerUserIdList != nil) {    
             for (NSString *key in providerUserIdList) {    
                 // providerUserId: key    
                 // playerId: [[providerUserIdList objectForKey:key] longlongValue];    
             }    
         }    
}];

回應 COPPA

《儿童在线隐私保护法案》(COPPA)是美国的一项联邦法律,旨在保护13岁以下儿童的在线隐私。为了响应COPPA,Hive 平台发布了 Hive SDK v4.10.0,其中包括 getAgeGateU13() API,用于查询用户是否在13岁以下。如果玩家年龄在13岁以下,该API将返回 true

範例代碼

API 參考: AuthV4.getAgeGateU13

using hive;    

Boolean ageGateU13 = AuthV4.getAgeGateU13();
#include "HiveAuthV4.h"

bool bAgeGateU13 = FHiveAuthV4::GetAgeGateU13();

API 參考: AuthV4 ::getAgeGateU13

#include <HIVE_SDK_Plugin/HIVE_CPP.h>    
    using namespace std;    
    using namespace hive;    

bool ageGateU13 = AuthV4::getAgeGateU13();

API 參考: AuthV4.getAgeGateU13

import com.hive.AuthV4    

val ageGateU13 = AuthV4.getAgeGateU13()

API 參考: AuthV4.INSTANCE.getAgeGateU13

import com.hive.AuthV4;    

boolean ageGateU13 = AuthV4.INSTANCE.getAgeGateU13();

API 參考: AuthV4Interface.getAgeGateU13

import HIVEService    

Bool ageGateU13 = AuthV4Interface.getAgeGateU13()

API 參考: HIVEAuthV4 getAgeGateU13

#import <HIVEService/HIVEService-Swift.h>    

BOOL ageGateU13 = [HIVEAuthV4 getAgeGateU13];

有什麼變化

如果 ageGateU13() 返回 true,則實現以下內容。

  • iOS
    • 當調用 AuthV4.setup()Auth.initialize() 時,推送通知的協議請求彈出窗口未顯示。
    • 推送 API 尚未實現。
  • Android
    • 當顯示退出彈出窗口時,更多遊戲按鈕未顯示。
    • 無法接收遠程推送,且推送 API 尚未實現。

檢查GDPR適用國家中16歲以下用戶的服務條款協議

從 Hive SDK v4 24.2.0 開始,您可以使用 Configuration.getAgeGateU16Agree() 方法來確定在受 GDPR(一般數據保護條例)影響的國家中,16 歲以下的用戶是否同意條款。如果返回的值為 true,則表示 16 歲以下的用戶已同意條款;如果為 false,則表示他們未同意。在使用第三方庫時,如果您需要根據用戶是否在 16 歲以下來限制應用功能,您可以利用 Configuration.getAgeGateU16Agree() 方法。

using hive;

Boolean ageGateU16Agree = Configuration.getAgeGateU16Agree();
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace std;
using namespace hive;

bool ageGateU16Agree = Configuration::getAgeGateU16Agree();
import com.hive.Configuration

val ageGateU16Agree = Configuration.ageGateU16Agree()
import com.hive.Configuration;

boolean ageGateU16Agree = Configuration.INSTANCE.getAgeGateU16Agree();
import HIVEService

var ageGateU16Agree: Bool = ConfigurationInterface.getAgeGateU16Agree()
#import <HIVEService/HIVEService-Swift.h>

BOOL ageGateU16 = [HIVEConfiguration getAgeGateU16Agree];

從 Hive SDK v4 24.3.0 開始,如果應用程序使用法定監護人同意確認條款,您可以通過調用Configuration.getLegalGuardianConsentAgree()方法來檢索應用程序用戶是否已獲得法定監護人同意。如果值為true,則表示已給予同意。

using hive;    

Boolean legalGuardianConsentAgree = Configuration.getLegalGuardianConsentAgree();
#include <HIVE_SDK_Plugin/HIVE_CPP.h>    
using namespace std;    
using namespace hive;    

bool ageGateU16Agree = Configuration::getLegalGuardianConsentAgree();
import com.hive.Configuration    

val legalGuardianConsentAgree = Configuration.legalGuardianConsentAgree()
import com.hive.Configuration;    

boolean legalGuardianConsentAgree = Configuration.INSTANCE.getLegalGuardianConsentAgree();
import HIVEService    

var legalGuardianConsentAgree: Bool = ConfigurationInterface.getLegalGuardianConsentAgree()
#import <HIVEService/HIVEService-Swift.h>    

BOOL legalGuardianConsentAgree = [HIVEConfiguration getLegalGuardianConsentAgree];

重新請求操作系統權限

遊戲所需的訪問權限列表在 AndroidManifest.xml 文件中進行組織。嘗試將一些權限作為相關 API 的字符串列表發送並使用它們。您可以檢查用戶是否選擇了特定權限。如果某些危險權限被拒絕,請確保顯示彈出窗口以再次請求訪問操作系統。其他權限根據用戶設備上的設置自動選擇或取消選擇。如果您輸入錯誤的權限或錯誤的單詞,系統將視為權限未在 AndroidManifest.xml 文件中聲明,並且不允許訪問這些權限。

Android 6.0 (API 等級 23) 支援此功能。如果操作系統是 iOS 或 Android API 等級早於 23,則 ResultAPI 會被發送為不支援。

Note

此功能僅適用於 Android。

範例代碼

API 參考: PlatformHelper .requestUserPermissions

String[] requestArray = {"android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.BLUETOOTH", "android.permission.READ_CONTACTS"};    
    List<String> requests = new List<String>(requestArray);    

    PlatformHelper.requestUserPermissions( requests, (ResultAPI result, String[] granted, String[] denied) => {    

         if (result.code == ResultAPI.Code.PlatformHelperOSNotSupported) {    
            //僅限Android    
         }    

         if (result.code == ResultAPI.Code.PlatformHelperOSVersionNotSupported) {    
             //Android OS版本不受支持。    
         }    

         if (granted != null && granted.Length > 0) {    
             foreach (String name in granted) {    
                 // List of permissions accepted among requests    
             }    
         }    

         if (denied != null && denied.Length > 0) {    
             foreach (String name denied) {    
                 // List of permissions denied among requests    
             }    
         }    
});
#include "HivePlatformHelper.h"

TArray<FString> Requests;
Requests.Add(TEXT("android.permission.WRITE_EXTERNAL_STORAGE"));
Requests.Add(TEXT("android.permission.READ_CONTACTS"));

FHivePlatformHelper::RequestUserPermissions(Requests, FHivePlatformHelperOnUserPermissionsDelegate::CreateLambda([this](const FHiveResultAPI& Result, const TArray<FString>& GrantedRequests, const TArray<FString>& DeniedRequests) {

        switch(Result.Code) {
                case FHiveResultAPI::ECode::Success: {
                        if (GrantedRequests.Num() > 0) {
                                // List of permissions accepted among requests
                        }
                        if (DeniedRequests.Num() > 0) {
                                // List of permissions denied among requests
                        }
                }
                        break;
                case FHiveResultAPI::ECode::PlatformHelperOSVersionNotSupported:
                        // Android OS version not supported.
                        break;
                default:
                        // Other exceptions
                        break;
        }
}));

API 參考: PlatformHelper ::requestUserPermissions

string requestArray[] = {"android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.BLUETOOTH", "android.permission.READ_CONTACTS"};    
    vector<string> requests(begin(requestArray), end(requestArray));    

    PlatformHelper::requestUserPermissions(requests, [=](ResultAPI const & result, vector<string> const & granted, vector<string> const & denied) {    

         if (result.code == hive::ResultAPI::PlatformHelperOSNotSupported) {    
             //Android only    
         }    

         if (result.code == hive::ResultAPI::PlatformHelperOSVersionNotSupported) {    
             //Android OS版本不支持。    
         }    

         if (!granted.empty()) {    
             for (string name : granted) {    
                 // List of permissions accepted among requests    
             }    
         }    

         if (!denied.empty()) {    
             for (string name : denied) {    
                 // List of permissions denied among requests    
             }    
         }    
});

API 參考: PlatformHelper.requestUserPermissions

import com.hive.PlatformHelper    
    import com.hive.ResultAPI    

    val requests = arrayListOf(    
         "android.permission.WRITE_EXTERNAL_STORAGE",    
         "android.permission.BLUETOOTH",    
         "android.permission.READ_CONTACTS"    
    )    

    PlatformHelper.requestUserPermissions(requests, object : PlatformHelper.RequestUserPermissionsListener {    
         override fun onRequestUserPermissions(result: ResultAPI, granted: List<String>, denied: List<String>) {    
             when (result.code) {    
                 ResultAPI.Code.Success -> {    
                     if (granted.isNotEmpty()) {    
                         // List of permissions accepted among requests    
                     }    
                     if (denied.isNotEmpty()) {    
                         // List of permissions denied among requests    
                     }    
                 }    
                 ResultAPI.Code.PlatformHelperOSVersionNotSupported -> {    
                     //Android OS版本不支援。    
                 }    
                 else -> {    
                     // 其他例外情況    
                 }    
             }    
         }    
})

API 參考: PlatformHelper .INSTANCE.requestUserPermissions

import com.hive.PlatformHelper;    
    import com.hive.ResultAPI;    

    List<String> requests = Arrays.asList(    
             "android.permission.WRITE_EXTERNAL_STORAGE",    
             "android.permission.BLUETOOTH",    
             "android.permission.READ_CONTACTS");    

    PlatformHelper.INSTANCE.requestUserPermissions(requests, (result, granted, denied) -> {    
         switch (result.getCode()) {    
             case Success:    
                 if (!granted.isEmpty()) {    
                     // List of permissions accepted among requests    
                 }    
                 if (!denied.isEmpty()) {    
                     // List of permissions denied among requests    
                 }    
                 break;    
             case PlatformHelperOSVersionNotSupported:    
                 //Android OS version not supported.    
                 break;    
             default:    
                 // other exception situations    
                 break;    
         }    
});

使用設備管理服務

設備管理服務會根據 Hive 控制台上的設置在登錄時自動實施。登錄後,遊戲會調用AuthV4類的showDeviceManagement()方法,並向用戶顯示設備管理列表。
當因設備身份驗證失敗而取消登錄時,具有設備管理服務的遊戲應該處理Result API的AuthV4NotRegisteredDevice代碼,以嘗試再次靜默登錄或執行登出。 有關設備管理服務的更多信息,請參閱操作指南:設備管理服務介紹

API 參考: AuthV4.showDeviceManagement

using hive;    

    AuthV4.showDeviceManagement((ResultAPI result) => {    
         if (result.isSuccess()) {    
             // 在展示設備管理 UI 後關閉    
         }    
}
#include "HiveAuthV4.h"

FHiveAuthV4::ShowDeviceManagement(FHiveAuthV4OnShowDeviceManagementDelegate::CreateLambda([this](const FHiveResultAPI& Result) {
        if (Result.IsSuccess()) {
                // Closed after exposing the device management UI 
        }
}));

API 參考: AuthV4 ::showDeviceManagement

#include <HIVE_SDK_Plugin/HIVE_CPP.h>    
    using namespace std;    
    using namespace hive;    

    AuthV4::showDeviceManagement([=](ResultAPI const & result) {    
         if (result.isSuccess()) {    
             // Closed after exposing the device management UI    
         }    
});

API 參考: AuthV4.showDeviceManagement

import com.hive.AuthV4    
    import com.hive.ResultAPI    

    AuthV4.showDeviceManagement(object : AuthV4.AuthV4ShowDeviceManagementListener {    
         override fun onAuthV4ShowDeviceManagement(result: ResultAPI) {    
             if (result.isSuccess) {    
                 // 關閉後顯示設備管理 UI    
             }    
         }    
})

API 參考: AuthV4.INSTANCE .showDeviceManagement

import com.hive.AuthV4;    
    import com.hive.ResultAPI;    

    AuthV4.INSTANCE.showDeviceManagement(result -> {    
         if (result.isSuccess()) {    
             // Closed after exposing the device management UI    
         }    
});

API 參考: AuthV4Interface .showDeviceManagement

import HIVEService    

    AuthV4Interface.showDeviceManagement() { result in    
         if result.isSuccess() {    
             // Closed after exposing the device management UI    
         }    
}

API 參考: HIVEAuthV4 showDeviceManagement

#import <HIVEService/HIVEService-Swift.h>    

    [HIVEAuthV4 showDeviceManagement: ^(HIVEResultAPI *result) {    
         if ([result isSuccess]) {    
             // Closed after exposing the device management UI    
         }    
}];

Google Play 遊戲成就與排行榜

要讓您的遊戲在 Google Play 遊戲中被推薦,您需要實現 Google Play 遊戲的成就和排行榜功能。

如果用戶使用 Google 帳戶在您的遊戲中登入,則會自動登入 Play 遊戲服務(PGS),因此成就和排行榜將可用。如果用戶在 PGS 的設置畫面中登出,玩家帳戶將與在遊戲中點擊登出按鈕的過程相同地登出。欲了解有關 PGS 功能的更多信息,請參閱 Google Play 遊戲服務指南

Note

在實現AuthV4Helper類時,

  • 如果用户在加载游戏时取消了对PGS的隐式登录,系统会记住该状态,并不会再次尝试隐式登录。即使在玩家会话有效时可以自动登录,系统仍会记住被拒绝的状态。

  • 如果用户没有登录PGS,成就的结果将不会发送到PGS。

這些內容符合 Google Play 遊戲服務指南。

發送玩家ID

如果您需要向 Google Play 游戏请求 PlayerID,请在 ProviderGoogle 类中实现 getGooglePlayerId() 方法。通过实现此方法,它会发送 PlayerID 以及 AuthCode,以验证会话密钥。

以下是示例代码。

API 參考: hive.ProviderGoogle.getGooglePlayerId

// Request the playerID from Google Play Games.
ProviderGoogle.getGooglePlyaerId((ResultAPI result, String googlePlayerId, String authCode)=>{
    if(result.isSuccess()){
        // Success in API call.
    }
});

API 參考: ProviderGoogle::getGooglePlayerId

// 從 Google Play 遊戲請求 playerID。
ProviderGoogle::getGooglePlayerId([=](ResultAPI const &result, std::string const &googlePlayerId, std::string const &authCode) {
    if (result.isSuccess())
    {
        // API 呼叫成功。
    }
});
#include "HiveProviderGoogle.h"

FHiveProviderGoogle::GetGooglePlayerId(FHiveProviderGoogleOnGooglePlayerIdDelegate::CreateLambda([this](const FHiveResultAPI& Result, const FString& GooglePlayerId, const FString& AuthCode) {
        if (Result.IsSuccess()) {
                // 成功呼叫 API。
        }
}));

API 參考: com.hive.ProviderGoogle.getGooglePlayerId

// 從 Google Play 遊戲請求 playerID。
ProviderGoogle.getGooglePlayerId(new ProviderGoogle.GooglePlayerIdListener() {
    @Override
    public void onPlayerIdResult(ResultAPI resultAPI, String googlePlayerId, String authCode) {
        if(resultAPI.isSuccess()){
            // API 呼叫成功。
        }
    }
});

成就

實現 ProviderGoogle 類別,以通過 Hive SDK 使用 Google Play 遊戲的 Achievement 功能。

請求揭示隱藏成就

要向当前登录的玩家揭示隐藏成就,请调用 achievementsReveal() 方法。它将没有效果,但会揭示 0% 的成就。 以下是示例代码。

API 參考: hive.ProviderGoogle.achievementsReveal

using hive;    
    //Achievement ID    
    String achievementId = "abcdef123456";    
    ProviderGoogle.achievementsReveal(achievementId, (ResultAPI result) => {    
      if (result.isSuccess()) {    
      // call successful    
      }    
});
#include "HiveProviderGoogle.h"

// 成就 ID 
FString AchievementId = TEXT("abcdef123456");
FHiveProviderGoogle::AchievementsReveal(AchievementId, FHiveProviderGoogleOnAchievementsDelegate::CreateLambda([this](const FHiveResultAPI& Result) {
        if (Result.IsSuccess()) {
                // API 调用成功 
        }
}));

API 參考: ProviderGoogle::achievementsReveal

#include <HIVE_SDK_Plugin/HIVE_CPP.h>    
    using namespace std;    
    using namespace hive;    
    //Achievement ID    
    string achievementId = "abcdef123456";    
    ProviderGoogle::achievementsReveal(achievementId, [=](ResultAPI const & result) {    
       if(result.isSuccess()){    
          // call successful    
        }    
});

API 參考: ProviderGoogle.achievementsReveal

import com.hive.ProviderGoogle    
    import com.hive.ResultAPI    
    //成就 ID    
    val achievementId = "abcdef123456"    
    ProviderGoogle.achievementsReveal(achievementId, object : ProviderGoogle.GoogleAchievementsListener {    
         override fun onAchievementsResult(resultAPI: ResultAPI) {    
             if (resultAPI.isSuccess) {    
                 // 呼叫成功    
             }    
         }    
})

API 參考: ProviderGoogle .INSTANCE.achievementsReveal

import com.hive.ProviderGoogle;    
    import com.hive.ResultAPI;    

    //成就 ID    
    String achievementId = "abcdef123456";    

    ProviderGoogle.INSTANCE.achievementsReveal(achievementId, resultAPI -> {    
         if (resultAPI.isSuccess()) {    
             // call successful    
         }    
});

解鎖成就的請求

要解鎖當前登錄玩家的成就,請調用 achievementsUnlock() 方法。此方法將標記 100% 的成就,無論其狀態如何;無論是隱藏還是未隱藏。以下是示例代碼。

API 參考: ProviderGoogle.achievementsUnlock

using hive;    
    //Achievement ID    
    String achievementId = "abcdef123456";    
    ProviderGoogle.achievementsUnlock(achievementId, (ResultAPI result) => {    
    if (result.isSuccess()) {    
    // call successful    
    }    
});

API 參考: ProviderGoogle::achievementsUnlock

#include <HIVE_SDK_Plugin/HIVE_CPP.h>    
    using namespace std;    
    using namespace hive;    
    //Achievement ID    
    string achievementId = "abcdef123456";    
    ProviderGoogle::achievementsUnlock(achievementId, [=](ResultAPI const & result) {    
    if(result.isSuccess()){    
           // call successful    
        }    
});

API 參考: ProviderGoogle.achievementsUnlock

import com.hive.ProviderGoogle    
    import com.hive.ResultAPI    
    //成就 ID    
    val achievementId = "abcdef123456"    
    ProviderGoogle.achievementsUnlock(achievementId, object : ProviderGoogle.GoogleAchievementsListener {    
         override fun onAchievementsResult(resultAPI: ResultAPI) {    
             if (resultAPI.isSuccess) {    
                 // 调用成功    
             }    
         }    
})

API 參考: ProviderGoogle .INSTANCE.achievementsUnlock

import com.hive.ProviderGoogle;    
    import com.hive.ResultAPI;    

    //成就 ID    
    String achievementId = "abcdef123456";    

    ProviderGoogle.INSTANCE.achievementsUnlock(achievementId, resultAPI -> {    
         if (resultAPI.isSuccess()) {    
             // call successful    
         }    
});

請求增進成就

要使用請求功能來增加成就,將成就值設置為參數,然後調用 achievementsIncrement() 方法。成就值是調用相應 API 時設置的值的總和,當總和達到最大值時,成就會自動達成。

以下是範例代碼。

API 參考: hive.ProviderGoogle.achievementsIncrement

using hive;    
    //Achievement ID    
    String achievementId = "abcdef123456";    
    // Achievement numbers    
    int value = 1;    
    ProviderGoogle.achievementsIncrement(achievementId, value, (ResultAPI result) => {    
      if (result.isSuccess()){    
      // call successful    
      }    
});
#include "HiveProviderGoogle.h"

//成就 ID 
FString AchievementId = TEXT("abcdef123456");
// 成就數字
int32 Value = 1;

FHiveProviderGoogle::AchievementsIncrement(AchievementId, Value, FHiveProviderGoogleOnAchievementsDelegate::CreateLambda([this](const FHiveResultAPI& Result) {
        if (Result.IsSuccess()) {
                // call successful
        }
}));

API 參考: ProviderGoogle::achievementsIncrement

#include <HIVE_SDK_Plugin/HIVE_CPP.h>    
    using namespace std;    
    using namespace hive;    
    //成就 ID    
    string achievementId = "abcdef123456";    
    // 成就數字    
    int value = 1;    
    ProviderGoogle::achievementsIncrement(achievementId, value, [=](ResultAPI const & result) {    
      if(result.isSuccess()){    
      // 呼叫成功    
      }    
});

API 參考: ProviderGoogle.achievementsIncrement

import com.hive.ProviderGoogle    
    import com.hive.ResultAPI    
    //成就 ID    
    val achievementId = "abcdef123456"    
    // 成就數字    
    val value = 1    
    ProviderGoogle.achievementsIncrement(achievementId, value, object : ProviderGoogle.GoogleAchievementsListener {    
         override fun onAchievementsResult(resultAPI: ResultAPI) {    
             if (resultAPI.isSuccess) {    
                 // 呼叫成功    
             }    
         }    
})

API 參考: ProviderGoogle .INSTANCE.achievementsIncrement

import com.hive.ProviderGoogle;    
    import com.hive.ResultAPI;    

    //成就 ID    
    String achievementId = "abcdef123456";    

    // 成就數字    
    int value = 1;    

    ProviderGoogle.INSTANCE.achievementsIncrement(achievementId, value, resultAPI -> {    
         if (resultAPI.isSuccess()) {    
             // call successful    
         }    
});

請求顯示成就列表(助手)

Note

SDK 4.7.0 提供了 Helper,它可以輕鬆比較用戶設備上的已登錄帳戶和與 PlayerID 同步的帳戶。如果兩個帳戶不相同,請參考 IdP Sync 頁面來處理此情況。

呼叫 showAchievements() 方法以請求 Google Play 遊戲的成就列表。

以下是示例代码。

API 参考: AuthV4.Helper.showAchievements

using hive;    
    AuthV4.Helper.showAchievements ((ResultAPI result, AuthV4.PlayerInfo playerInfo) => {    
      switch (result.code) {    
        case ResultAPI.Code.Success:    
          // Deliver Success with achievement indication    
          break;    
        case ResultAPI.Code.AuthV4ConflictPlayer:    
          // account conflict    
          break;    
        case ResultAPI.Code.AuthV4GoogleLogout:    
          //TODO:    
          // After logging out of Google Play, log out of the game    
          // Relaunching the game must be handled by the development studio    
          break;    
        default:    
          // other exception situations    
          break;    
      }    
});
#include "HiveAuthV4.h"

FHiveAuthV4::Helper::ShowAchievements(FHiveAuthV4HelperDelegate::CreateLambda([this](const FHiveResultAPI& Result, const TOptional<FHivePlayerInfo>& PlayerInfo) {
        switch (Result.Code) {
                case FHiveResultAPI::ECode::Success:
                        // 交付成功并显示成就指示
                        break;
                case FHiveResultAPI::ECode::AuthV4ConflictPlayer:
                        // 帐号冲突
                        break;
                case FHiveResultAPI::ECode::AuthV4GoogleLogout:
                        // TODO:
                        // 登出 Google Play 后,登出游戏
                        // 重新启动游戏必须由开发工作室处理
                        break;
                default:
                        // 其他异常情况
                        break;
        }
}));

API 參考: AuthV4 ::Helper::showAchievements

#include <HIVE_SDK_Plugin/HIVE_CPP.h>    
    using namespace std;    
    using namespace hive;    
    AuthV4::Helper::showAchievements([=](ResultAPI const & result, shared_ptr playerInfo) {    
      switch (result.code) {    
        case ResultAPI::Success:    
          // Deliver Success with achievement indication    
          break;    
        case ResultAPI::AuthV4ConflictPlayer:    
          // account conflict    
          break;    
        case ResultAPI::AuthV4GoogleLogout:    
          //TODO:    
          // After logging out of Google Play, log out of the game    
          // Relaunching the game must be handled by the development studio    
          break;    
        default:    
          // other exception situations    
          break;    
      }    
});

API 參考: AuthV4.Helper.showAchievements

import com.hive.AuthV4    
    import com.hive.ResultAPI    
    AuthV4.Helper.showAchievements(object : AuthV4.Helper.AuthV4HelperListener {    
         override fun onAuthV4Helper(result: ResultAPI, playerInfo: AuthV4.PlayerInfo?) {    
             when (result.code) {    
                 ResultAPI.Code.Success -> {    
                     // Deliver Success with achievement indication    
                 }    
                 ResultAPI.Code.AuthV4ConflictPlayer -> {    
                     // 帳戶衝突    
                 }    
                 ResultAPI.Code.AuthV4GoogleLogout -> {    
                     //TODO:    
                     // 登出 Google Play 後,登出遊戲    
                     // 重新啟動遊戲必須由開發工作室處理    
                 }    
                 else -> {    
                     // 其他例外情況    
                 }    
             }    
         }    
})

API 參考: AuthV4.Helper.INSTANCE.showAchievements

import com.hive.AuthV4;    
    import com.hive.ResultAPI;    

    AuthV4.Helper.INSTANCE.showAchievements((result, playerInfo) -> {    
         switch (result.getCode()) {    
             case Success:    
                 // 交付成功并指示成就    
                 break;    
             case AuthV4ConflictPlayer:    
                 // 账户冲突    
                 break;    
             case AuthV4GoogleLogout:    
                 //TODO:    
                 // 从Google Play注销后,注销游戏    
                 // 重新启动游戏必须由开发工作室处理    
                 break;    
             default:    
                 // 其他异常情况    
                 break;    
         }    
});
Warning

如果用户从Play Games Services的设置屏幕注销,玩家账户将被注销,并作为回调发送名为ResultAPI.Code.AuthV4GoogleLogout的错误代码。注销完成后,将显示注销弹出窗口,并将显示更改为游戏标题。


請求顯示成就列表 (Auth v4)

呼叫 showAchievements() 方法以請求 Google Play 遊戲的成就列表。

以下是示例代码。

API 参考: ProviderGoogle .showAchievements

using hive;    
    ProviderGoogle.showAchievements((ResultAPI result) => {    
      switch (result.code) {    
        case ResultAPI.Code.Success:    
          // Deliver Success with achievement indication    
          break;    
        case ResultAPI.Code.AuthV4GoogleLogout:    
          //TODO:    
          // After logging out of Google Play, log out of the game    
          // Relaunching the game must be handled by the development studio    
          break;    
        default:    
          // other exception situations    
          break;    
      }    
});
#include "HiveProviderGoogle.h"

FHiveProviderGoogle::ShowAchievements(FHiveProviderGoogleOnLeaderboardsDelegate::CreateLambda([this](const FHiveResultAPI& Result) {
                case FHiveResultAPI::ECode::Success:
                        // 传递成功并显示成就
                        break;
                case FHiveResultAPI::ECode::AuthV4GoogleLogout:
                        // TODO:
                        // 在Google Play注销后执行游戏注销
                        // 游戏重新启动由开发工作室处理
                        break;
                default:
                        // 其他异常情况
                        break;
}));

API 參考: ProviderGoogle ::showAchievements

#include <HIVE_SDK_Plugin/HIVE_CPP.h>    
    using namespace std;    
    using namespace hive;    
    ProviderGoogle::showAchievements([=](ResultAPI const & result) {    
      switch (result.code) {    
        case ResultAPI::Success:    
          // Deliver Success with achievement indication    
          break;    
        case ResultAPI::AuthV4GoogleLogout:    
          //TODO:    
          // After logging out of Google Play, log out of the game    
          // Relaunching the game must be handled by the development studio    
          break;    
        default:    
          // other exception situations    
          break;    
      }    
});

API 參考: ProviderGoogle.showAchievements

import com.hive.ProviderGoogle    
    import com.hive.ResultAPI    
    ProviderGoogle.showAchievements(object : ProviderGoogle.GoogleAchievementsListener {    
         override fun onAchievementsResult(resultAPI: ResultAPI) {    
             when(resultAPI.code) {    
                 ResultAPI.Code.Success -> {    
                     // Deliver Success with achievement indication    
                 }    
                 ResultAPI.Code.AuthV4GoogleLogout -> {    
                     //TODO:    
                     // After logging out of Google Play, log out of the game    
                     // Relaunching the game must be handled by the development studio    
                 }    
                 else -> {    
                     // other exception situations    
                 }    
             }    
         }    
})

API 參考: ProviderGoogle.INSTANCE.showAchievements

import com.hive.ProviderGoogle;    
    import com.hive.ResultAPI;    

    ProviderGoogle.INSTANCE.showAchievements(resultAPI -> {    
         switch (resultAPI.getCode()) {    
             case Success:    
                 // Deliver Success with achievement indication    
                 break;    
             case AuthV4GoogleLogout:    
                 //TODO:    
                 // After logging out of Google Play, log out of the game    
                 // Relaunching the game must be handled by the development studio    
                 break;    
             default:    
                 // other exception situations    
                 break;    
         }    
});
Warning

如果用戶在 Play Games Services 的設置屏幕上登出,將作為回調發送名為 ResultAPI.Code.AuthV4GoogleLogout 的錯誤代碼。一旦發送此錯誤,請確保按照遊戲中點擊登出按鈕時的過程進行編碼。

排行榜

實現 ProviderGoogle 類以通過 Hive SDK 使用 Google Play 遊戲的 Leaderboard 功能。

排行榜分數更新

呼叫 leaderboardsSubmitScore() 方法以請求 Google Play 遊戲的排行榜分數更新。

以下是示例代码。

API 參考: hive.ProviderGoogle.leaderboardsSubmitScore

using hive    

    // 排行榜 ID    
    String leaderboardId = "12345abcde";    

    // 排行榜分數    
    long score = 100;    
    ProviderGoogle.leaderboardsSubmitScore(leaderboardId, score, (ResultAPI result) => {    
      if (result.isSuccess()) {    
      // API 呼叫成功    
      }    
});
#include "HiveProviderGoogle.h"

// 排行榜 ID
FString LeaderboardId = TEXT("12345abcde");

// 排行榜分數
int64 Score = 100;

FHiveProviderGoogle::LeaderboardsSubmitScore(LeaderboardId, Score, FHiveProviderGoogleOnLeaderboardsDelegate::CreateLambda([this](const FHiveResultAPI& Result) {
        if (Result.IsSuccess()) {
                // API call successful 
        }
}));

API 參考: ProviderGoogle::leaderboardsSubmitScore

#include <HIVE_SDK_Plugin/HIVE_CPP.h>    
    using namespace std;    
    using namespace hive;    
    // Leaderboard ID    
    string leaderboardId = "12345abcde";    

    // 排行榜分數    
    long score = 100;    

    ProviderGoogle::leaderboardsSubmitScore(leaderboardId, score, [=](ResultAPI const & result) {    
       if (result.isSuccess()) {    
          // API call successful    
        }    
});

API 參考: ProviderGoogle.leaderboardsSubmitScore

import com.hive.ProviderGoogle    
    import com.hive.ResultAPI    
    // 排行榜 ID    
    val leaderboardId = "12345abcde"    
    // 排行榜分数    
    val score = 100L    
    ProviderGoogle.leaderboardsSubmitScore(leaderboardId, score, object : ProviderGoogle.GoogleLeaderboardsListener {    
         override fun onLeaderboardsResult(resultAPI: ResultAPI) {    
             if (resultAPI.isSuccess) {    
                 // API 调用成功    
             }    
         }    
})

API 參考: com.hive.ProviderGoogle.leaderboardsSubmitScore

import com.hive.ProviderGoogle;    
    import com.hive.ResultAPI;    

    // 排行榜 ID    
    String leaderboardId = "12345abcde";    

    // 排行榜分數    
    long score = 100;    

    ProviderGoogle.INSTANCE.leaderboardsSubmitScore(leaderboardId, score, resultAPI -> {    
         if (resultAPI.isSuccess()) {    
             // API call successful    
         }    
});

請求顯示排行榜列表(助手)

呼叫 showLeaderboards() 方法以請求 Google Play 遊戲的排行榜列表。
以下是範例代碼。

API 參考: hive.AuthV4.Helper.showLeaderboard

using hive;    
    AuthV4.Helper.showLeaderboard ((ResultAPI result, AuthV4.PlayerInfo playerInfo) => {    
       switch (result.code) {    
         case ResultAPI.Code.Success:    
           // Deliver Success with leaderboard display    
           break;    
         case ResultAPI.Code.AuthV4ConflictPlayer:    
           // account conflict    
           break;    
         case ResultAPI.CodeAuthV4GoogleLogout:    
    //TODO:    
           // After logging out of Google Play, log out of the game    
           // Relaunching the game must be handled by the development studio    
           break;    
         default:    
           // other exception situations    
           break;    
       }    
});
#include "HiveAuthV4.h"

FHiveAuthV4::Helper::ShowLeaderboard(FHiveAuthV4HelperDelegate::CreateLambda([this](const FHiveResultAPI& Result, const TOptional<FHivePlayerInfo>& PlayerInfo) {
                case FHiveResultAPI::ECode::Success:
                        // Deliver Success with leaderboard display
                        break;
                case FHiveResultAPI::ECode::AuthV4ConflictPlayer:
                        // account conflict 
                        break;
                case FHiveResultAPI::ECode::AuthV4GoogleLogout:
                        // TODO:
                        // After logging out of Google Play, log out of the game    
          // Relaunching the game must be handled by the development studio
                        break;
                default:
                        // 其他异常情况
                        break;
}));

API 參考: com.hive.AuthV4.Helper.showLeaderboard

#include <HIVE_SDK_Plugin/HIVE_CPP.h>    
    using namespace std;    
    using namespace hive;    
    AuthV4::Helper::showLeaderboard([=](ResultAPI const & result, shared_ptr playerInfo) {    
    switch (result.code) {    
           case ResultAPI::Success:    
             // Deliver Success with leaderboard display    
             break;    
           case ResultAPI::AuthV4ConflictPlayer:    
             // account conflict    
             break;    
           case ResultAPI::AuthV4GoogleLogout:    
    //TODO:    
             // After logging out of Google Play, log out of the game    
             // Relaunching the game must be handled by the development studio    
             break;    
           default:    
             break;    
         }    
});

API 參考: Helper.showLeaderboard

import com.hive.AuthV4    
    import com.hive.ResultAPI    
    AuthV4.Helper.showLeaderboard(object : AuthV4.Helper.AuthV4HelperListener {    
         override fun onAuthV4Helper(result: ResultAPI, playerInfo: AuthV4.PlayerInfo?) {    
             when (result.code) {    
                 ResultAPI.Code.Success -> {    
                     // 交付成功并显示排行榜    
                 }    
                 ResultAPI.Code.AuthV4ConflictPlayer -> {    
                     // 帐户冲突    
                 }    
                 ResultAPI.Code.AuthV4GoogleLogout -> {    
                     //TODO:    
                     // 登出 Google Play 后,登出游戏    
                     // 重新启动游戏必须由开发工作室处理    
                 }    
                 else -> {    
    // 其他异常情况    
    }    
             }    
         }    
})

API 參考: AuthV4.Helper.INSTANCE.showLeaderboard

import com.hive.AuthV4;
import com.hive.ResultAPI;

AuthV4.Helper.INSTANCE.showLeaderboard((result, playerInfo) -> {
    switch (result.getCode()) {
        case Success:
            // Deliver Success with leaderboard display
            break;
        case AuthV4ConflictPlayer:
            // account conflict
            break;
        case AuthV4GoogleLogout:
            //TODO:
            // After logging out of Google Play, log out of the game
            // Relaunching the game must be handled by the development studio
            break;
        default:
            // other exception situations
            break;
    }
});
Warning

如果用户从Play Games Services的设置屏幕注销,玩家账户将被注销,并作为回调发送名为ResultAPI.Code.AuthV4GoogleLogout的错误代码。注销完成后,将显示注销弹出窗口,并且显示更改为游戏标题。


請求顯示排行榜列表 (Auth v4)

呼叫 showLeaderboards() 方法以請求 Google Play 遊戲的排行榜列表。

以下是示例代碼。

API 參考: hive.ProviderGoogle.showLeaderboards

using hive;    

    ProviderGoogle.showLeaderboards(onLeaderboardsResult, (ResultAPI result) => {    
    switch (result.code) {    
         case ResultAPI.Code.Success:    
           // Deliver Success with leaderboard display    
           break;    
         case ResultAPI.CodeAuthV4GoogleLogout:    
           //TODO:    
           // After logging out of Google Play, log out of the game    
           // Relaunching the game must be handled by the development studio    
           break;    
         default:    
           // other exception situations    
           break;    
       }    
});
#include "HiveProviderGoogle.h"

FHiveProviderGoogle::ShowLeaderboard(FHiveProviderGoogleOnLeaderboardsDelegate::CreateLambda([this](const FHiveResultAPI& Result) {
                    case FHiveResultAPI::ECode::Success:
                        // Deliver Success with leaderboard display 
                        break;
                case FHiveResultAPI::ECode::AuthV4GoogleLogout:
                        // TODO:
                        // After logging out of Google Play, log out of the game    
          // Relaunching the game must be handled by the development studio 
                        break;
                default:
                        // other exception situations 
                        break; 
}));

API 參考: ProviderGoogle::showLeaderboards

#include <HIVE_SDK_Plugin/HIVE_CPP.h>    
    using namespace std;    
    using namespace hive;    
    ProviderGoogle::showLeaderboard([=](ResultAPI const & result) {    
    switch (result.code) {    
           case ResultAPI::Success:    
             // Deliver Success with leaderboard display    
             break;    
           case ResultAPI::AuthV4GoogleLogout:    
             //TODO:    
             // After logging out of Google Play, log out of the game    
             // Relaunching the game must be handled by the development studio    
             break;    
           default:    
    // other exception situations    
             break;    
         }    
});

API 參考: ProviderGoogle.showLeaderboards

import com.hive.ProviderGoogle    
    import com.hive.ResultAPI    
    ProviderGoogle.showLeaderboards(object : ProviderGoogle.GoogleLeaderboardsListener {    
         override fun onLeaderboardsResult(resultAPI: ResultAPI) {    
             when(resultAPI.code) {    
                 ResultAPI.Code.Success -> {    
                     // Deliver Success with leaderboard display    
                 }    
                 ResultAPI.Code.AuthV4GoogleLogout -> {    
                     //TODO:    
                     // After logging out of Google Play, log out of the game    
                     // Relaunching the game must be handled by the development studio    
                 }    
                 else -> {    
    // other exception situations    
    }    
             }    
         }    
})

API 參考: com.hive.ProviderGoogle.showLeaderboards

import com.hive.ProviderGoogle;    
    import com.hive.ResultAPI;    

    ProviderGoogle.INSTANCE.showLeaderboards(resultAPI -> {    
         switch (resultAPI.getCode()) {    
             case Success:    
                 // Deliver Success with leaderboard display    
                 break;    
             case AuthV4GoogleLogout:    
                 //TODO:    
                 // After logging out of Google Play, log out of the game    
                 // Relaunching the game must be handled by the development studio    
                 break;    
             default:    
                  // other exception situations    
                 break;    
         }    
});
Warning

如果用戶在 Play Games Services 的設置畫面中登出,將作為回調發送名為 ResultAPI.Code.AuthV4GoogleLogout 的錯誤代碼。一旦發送此錯誤,請確保按照遊戲中點擊登出按鈕時的過程進行編碼。

蘋果遊戲中心遊戲成就與排行榜

要讓您的遊戲在 Apple Game Center 上被推薦,您需要應用 Apple Game Center 的成就和排行榜功能。

無論用戶的身份驗證狀態如何,Apple Game Center 的兩個功能是由 Hive SDK 提供的。也就是說,成就和排行榜使用 Apple Game Center 帳戶,但成就和排行榜使用 Apple Game Center 帳戶,但該帳戶可能未與 Hive 帳戶鏈接或與玩家當前登錄的 Hive 帳戶不同。

有關 Apple 遊戲中心功能的更多資訊,請參閱 Apple 遊戲中心指南

Note

iOS Enterprise 不支持 Apple Game Center。

成就

實現 ProviderApple 類別,以通過 Hive SDK 使用 Apple Game Center 的成就功能。

請求成就列表

要加载成就列表,请调用 loadAchievements() 方法。

以下是示例代码。

API 參考: hive.ProviderApple.loadAchievements

// Request achievement list to Provider Apple
// using hive


// 回调处理程序管理对 Apple 提供者的成就列表请求
public void onLoadAchievements(ResultAPI result, List achievementList) {

Logger.log("ProviderTestView.onLoadAchievements() 回调\nresult = " + result.toString() + "\n");

if (result.isSuccess() != true) 
    return;
}

// 向提供者 Apple 请求成就列表
ProviderApple.loadAchievements(onLoadAchievements);
#include "HiveProviderApple.h"

FHiveProviderApple::LoadAchievements(FHiveProviderAppleOnLoadAchievements::CreateLambda([this](const FHiveResultAPI& Result, const TArray<FHiveProviderAppleAchievement>& Achievements) {
        if (Result.IsSuccess())
        {
                // API call success
        }
}));

API 參考: ProviderApple::loadAchievements

// 向提供者 Apple 請求成就列表
ProviderApple::loadAchievements([=](ResultAPI const & result,std::vector<ProviderAppleAchievement>; const & achievements) {
    // 結果回調
    cout<<"ProviderApple::loadAchievements() Callback"<<endl<<result.toString()<<endl;


    if (result.isSuccess() != true)
        return;

});

API 參考: HIVEProviderApple::showAchievements:

import HIVEService
ProviderApple.loadAchievements { result, achievements in
    if result.isSuccess() { ... }
}

API 參考: HIVEProviderApple::showAchievements:

// 向 Apple 提供者请求成就列表
[HIVEProviderApple loadAchievements:^(HIVEResultAPI *result, NSArray<HIVEProviderAppleAchievement *>; *achievements) {


    Loggerd(@"HIVEProviderApple.loadAchievements:\nresult = %@\nachievements = %@", result, achievements);

    if (result.isSuccess) {

    }
    else {

    }

    }];

請求報告成就

要報告成就,請調用 reportAchievement() 方法,並將參數設置為 成就率成功成就的通知橫幅曝光

以下是範例代碼。

API 參考: hive .ProviderApple.reportAchievement

using hive;    

    //成就达成 %. 成就完成于 100    
    String achievementPercent = "100";    
    // 成就成功时是否显示顶部横幅。默认值为 false    
    Boolean isShow = true;    
    //成就 ID    
    String achievementId = "com.hivesdk.achievement.10hit";    

    ProviderApple.reportAchievement(achievementPercent, isShow, achievementId, (ResultAPI result) => {    
         if (result.isSuccess()) {    
             // call successful    
         }    
});
#include "HiveProviderApple.h"

//成就達成 %. 成就完成於 100 
FString Percent = TEXT("100");
// 成就成功時是否顯示頂部橫幅。默認為 false  
bool bIsShow = true;
// 成就 ID
FString AchievementId = TEXT("com.hivesdk.achievement.10hit");

FHiveProviderApple::ReportAchievement(Percent, bIsShow, AchievementId, FHiveProviderAppleOnReportAchievement::CreateLambda([this](const FHiveResultAPI& Result) {
        if (Result.IsSuccess()) {
                // API call successful
        }
}));

API 參考: ProviderApple ::reportAchievement

#include <HIVE_SDK_Plugin/HIVE_CPP.h>    
    using namespace std;    
    using namespace hive;    

    //成就達成 %. 成就完成於 100    
    string achievementPercent = "100";    
    // 成就成功時是否顯示頂部橫幅。 默認為 false    
    bool isShow = true;    
    //成就 ID    
    string achievementId = "com.hivesdk.achievement.10hit";    

    ProviderApple::reportAchievement(achievementPercent, isShow, achievementId, [=](ResultAPI const & result) {    
         if (result.isSuccess()) {    
             // call successful    
         }    
});

API 參考: ProviderApple.reportAchievement

import HIVEService    

    //成就達成 %. 成就完成於 100    
    let achievementPercent = "100"    
    // 成就成功時是否顯示頂部橫幅。默認為 false    
    let isShow = true    
    // 成就 ID    
    let achievementId = "com.hivesdk.achievement.10hit"    

    ProviderApple.reportAchievement(achievementPercent, showsCompletionBanner: isShow, achievementIdentifier: achievementId) { result in    
         if result.isSuccess() {    
             // call successful    
         }    
}

API 參考: HIVEProviderApple reportAchievement

#import <HIVEService/HIVEService-Swift.h>    

    //成就達成 %. 當達到 100 時成就完成    
    NSString *achievementPercent = @"100";    
    // 成就成功時是否顯示頂部橫幅。默認為 NO    
    BOOL isShow = YES;    
    //成就 ID    
    NSString *achievementId = @"com.hivesdk.achievement.10hit";    

    [HIVEProviderApple reportAchievement: achievementPercent showsCompletionBanner: isShow achievementIdentifier: achievementId handler: ^(HIVEResultAPI *result) {    
         if ([result isSuccess]) {    
             // call successful    
         }    
}];

請求顯示成就 UI (助手)

Note

SDK 4.7.0 提供了 Helper,它可以轻松比较用户设备上的已登录帐户和 PlayerID 同步的帐户。如果两个帐户不相同,请参考 IdP Sync 页面来处理此情况。

要顯示成就 UI,請調用 showAchievements() 方法。

以下是示例代碼。

API 參考: hive.AuthV4.Helper.showAchievements

using hive;

AuthV4.Helper.showAchievements ((ResultAPI result, AuthV4.PlayerInfo playerInfo) => {
switch (result.code) {
    case ResultAPI.Code.Success:
    // Deliver Success with achievement indication
    break;
    case ResultAPI.Code.AuthV4ConflictPlayer:
    // account conflict
    break;
    case ResultAPI.Code.AuthV4GoogleLogout:
    //TODO:
    // After logging out of Google Play, log out of the game
    // Relaunching the game must be handled by the development studio
    break;
    default:
    // other exception situations
    break;
}
});
#include "HiveAuthV4.h"

FHiveAuthV4::Helper::ShowAchievements(FHiveAuthV4HelperDelegate::CreateLambda([this](const FHiveResultAPI& Result, const TOptional<FHivePlayerInfo>& PlayerInfo) {
        switch (Result.Code) {
                case FHiveResultAPI::ECode::Success:
                        // 交付成功并指示成就
                        break;
                case FHiveResultAPI::ECode::AuthV4ConflictPlayer:
                        // 账户冲突
                        break;
                default:
                        // 其他异常情况
                        break;
        }
}));

API 參考: AuthV4 ::Helper::showAchievements

#include <HIVE_SDK_Plugin/HIVE_CPP.h>    
    using namespace std;    
    using namespace hive;    
    AuthV4::Helper::showAchievements([=](ResultAPI const & result, shared_ptr playerInfo) {    
      switch (result.code) {    
        case ResultAPI::Success:    
          // Deliver Success with achievement indication    
          break;    
        case ResultAPI::AuthV4ConflictPlayer:    
          // account conflict    
          break;    
        case ResultAPI::AuthV4GoogleLogout:    
          //TODO:    
          // After logging out of Google Play, log out of the game    
          // Relaunching the game must be handled by the development studio    
          break;    
        default:    
          // other exception situations    
          break;    
      }    
});

API 參考: AuthV4Interface .helper().showAchievements

// 如果當前登錄的 Hive 帳戶未連接到 GameCenter    
    // 自動嘗試連接到 GameCenter    

    import HIVEService    

    AuthV4Interface.helper().showAchievements() { result, playerInfo in    
         switch result.getCode() {    
             case .success:    
                 // Deliver Success with achievement indication    
             case .authV4ConflitPlayer:    
                 // account conflict    
             default:    
                 break    
         }    
}

API 參考: [ HIVEAuthV4 helper] showAchievements

// 如果當前登錄的 Hive 帳戶未連接到 GameCenter    
    // 自動嘗試連接到 GameCenter    

    #import <HIVEService/HIVEService-Swift.h>    

    [[HIVEAuthV4 helper] showAchievements: ^(HIVEResultAPI *result, HIVEPlayerInfo *playerInfo) {    
         switch ([result getCode]) {    
             case HIVEResultAPICodeSuccess:    
                 // Deliver Success with achievement indication    
                 break;    
             case HIVEResultAPICodeAuthV4ConflictPlayer:    
                 // account conflict    
                 break;    
             default:    
                 // other exception situations    
                 break;    
         }    
}];

請求顯示成就 UI

要顯示成就 UI,請調用 showAchievements() 方法。

以下是示例代码。

API 參考: ProviderApple.showAchievements

using hive;    

    ProviderApple.showAchievements((ResultAPI result) {    
         if (result.isSuccess()) {    
             // call successful    
         }    
});
#include "HiveProviderApple.h"

FHiveProviderApple::ShowAchievements(FHiveProviderAppleOnShowAchievement::CreateLambda([this](const FHiveResultAPI& Result) {
        if (Result.IsSuccess()) {
                // call successful
        }
}));

API 參考: ProviderApple::showAchievements

#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace std;
using namespace hive;

ProviderApple::showAchievements([=](ResultAPI const & result) {
    if (result.isSuccess()) {
        // call successful
    }
});

API 參考: ProviderApple.showAchievements

import HIVEService    

    ProviderApple.showAchievements() { result in    
         if result.isSuccess() {    
             // call successful    
         }    
}

API 參考: HIVEProviderApple showAchievements

#import <HIVEService/HIVEService-Swift.h>    

    [HIVEProviderApple showAchievements: ^(HIVEResultAPI *result) {    
         if ([result isSuccess]) {    
             // call successful    
         }    
}];

重置成就的請求

要重置成就,请实现resetAchievements()方法。

以下是示例代码。

API 參考: hive.ProviderApple.resetAchievements

using hive;

ProviderApple.resetAchievements((ResultAPI result) => {
    if (result.isSuccess()) {
        // call successful
    }
});
#include "HiveProviderApple.h"

FHiveProviderApple::ResetAchievements(FHiveProviderAppleOnResetAchievement::CreateLambda([this](const FHiveResultAPI& Result) {
        if (Result.IsSuccess()) {
                // API call successful
        }
}));

API 參考: ProviderApple ::resetAchievements

#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace std;
using namespace hive;

ProviderApple::resetAchievements([=](ResultAPI const & result) {
    if (result.isSuccess()) {
        // call successful
    }
});

API 參考: resetAchievements(_:)

import HIVEService

ProviderApple.resetAchievements() { result in
    if result.isSuccess() {
        // call successful
    }
}

API 參考: HIVEProviderApple showAchievements<

#import <HIVEService/HIVEService-Swift.h>    

    [HIVEProviderApple resetAchievements: ^(HIVEResultAPI *result) {    
         if ([result isSuccess]) {    
             // call successful    
         }    
}];

排行榜

實作 ProviderApple 類別,以透過 Hive SDK 使用 Leaderboard 功能的 Apple Game Center。

請求報告排行榜分數

要將排行榜分數報告給 Apple Game Center,請調用 reportScore() 方法。
以下是示例代碼。

API 參考: hive .ProviderApple.reportScore

using hive;    

    String playerScore = "1234";    
    String leaderBoardId = "com.hivesdk.leaderboard.10hit";    

    ProviderApple.reportScore(playerScore, leaderBoardId, (ResultAPI result) => {    
         if (result.isSuccess()) {    
             // call successful    
         }    
});
#include "HiveProviderApple.h"

FString 玩家得分 = TEXT("1234");
FString 排行榜ID = TEXT("com.hivesdk.leaderboard.10hit");

FHiveProviderApple::ReportScore(PlayerScore, LeaderBoardId, FHiveProviderAppleOnReportLeaderboard::CreateLambda([this](const FHiveResultAPI& Result) {
        if (Result.IsSuccess()) {
                // API call successful
        }
}));

API 參考: ProviderApple ::reportScore

#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace std;
using namespace hive;

string playerScore = "1234";
string leaderBoardId = "com.hivesdk.leaderboard.10hit";

ProviderApple::reportScore(playerScore, leaderBoardId, [=](ResultAPI const & result) {
    if (result.isSuccess()) {
        // call successful
    }
});

API 參考: HIVEProviderApple::reportScore:leaderboardIdentifier:handler:

import HIVEService    

    let playerScore = "1234"    
    let leaderBoardId = "com.hivesdk.leaderboard.10hit"    

    ProviderApple.reportScore(playScore, leaderboardIdentifier: leaderboardId) { result in    
         if result.isSuccess() {    
             // call successful    
         }    
}

API 參考: HIVEProviderApple ::reportScore:leaderboardIdentifier:handler:

#import <HIVEService/HIVEService-Swift.h>    

    NSString *playerScore = @"1234";    
    NSString *leaderBoardId = "com.hivesdk.leaderboard.10hit";    

    [HIVEProviderApple reportScore: playerScore leaderboardIdentifier: leaderBoardId handler: ^(HIVEResultAPI *result) {    
         if ([result isSuccess]) {    
             // call successful    
         }    
}];

請求顯示排行榜 UI (助手)

要顯示排行榜 UI,請調用 showLeaderboard() 方法。

以下是示例代码。

API 參考: hive .AuthV4.Helper.showLeaderboard

// 如果當前登錄的 Hive 帳戶未連接到 GameCenter    
    // 自動嘗試連接到 GameCenter    

    使用 hive;    

    AuthV4.Helper.showLeaderboard((ResultAPI result, AuthV4.PlayerInfo playerInfo) => {    
         switch (result.code) {    
             case ResultAPI.Code.Success:    
                 // Deliver Success with leaderboard display    
                 break;    
             case ResultAPI.Code.AuthV4ConflictPlayer:    
                 // account conflict    
                 break;    
             default:    
                 // other exception situations    
                 break;    
         }    
});

API 參考: AuthV4 ::Helper::showLeaderboard

// 如果當前登錄的 Hive 帳戶未連接到 GameCenter
// 自動嘗試連接到 GameCenter

#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace std;
using namespace hive;

AuthV4::Helper::showLeaderboard([=](ResultAPI const & result, shared_ptr<PlayerInfo> playerInfo) {
    switch (result.code) {
        case ResultAPI::Success:
            // Deliver Success with leaderboard display
            break;
        case ResultAPI::AuthV4ConflictPlayer:
            // account conflict
            break;
        default:
            break;
    }
});

API 參考: showLeaderboard

// 如果當前登錄的 Hive 帳戶未連接到 GameCenter    
    // 自動嘗試連接到 GameCenter    

    import HIVEService    

    AuthV4Interface.helper().showLeaderboard() { result, playerInfo in    
         switch result.getCode() {    
             case .success:    
                 // Deliver Success with leaderboard display    
             case .authV4ConflictPlayer:    
                 // account conflict    
             default:    
                 break    
         }    
}

API 參考: HIVEProviderApple ::showLeaderboard:

// 如果當前登錄的 Hive 帳戶未連接到 GameCenter    
    // 自動嘗試連接到 GameCenter    

    #import <HIVEService/HIVEService-Swift.h>    

    [[HIVEAuthV4 helper] showLeaderboard: ^(HIVEResultAPI *result, HIVEPlayerInfo *playerInfo) {    
         switch ([result getCode]) {    
             case HIVEResultAPICodeSuccess:    
                 // Deliver Success with leaderboard display    
                 break;    
             case HIVEResultAPICodeAuthV4ConflictPlayer:    
                 // account conflict    
                 break;    
             default:    
                 // other exception situations    
                 break;    
         }    
}];

請求顯示排行榜 UI

要顯示排行榜 UI,請調用 showLeaderboard() 方法。

以下是示例代码。

API 參考: hive .ProviderApple.showLeaderboard

using hive;    

    ProviderApple.showLeaderboard((ResultAPI result) => {    
         if (result.isSuccess()) {    
             // call successful    
         }    
});
#include "HiveProviderApple.h"

FHiveProviderApple::ShowLeaderboard(FHiveProviderAppleOnShowLeaderboard::CreateLambda([this](const FHiveResultAPI& Result) {
        if (Result.IsSuccess()) {
                // API call successful
        }
}));

API 參考: ProviderApple ::showLeaderboard

#include <HIVE_SDK_Plugin/HIVE_CPP.h>    
    using namespace std;    
    using namespace hive;    

    ProviderApple::showLeaderboard([=](ResultAPI const & result) {    
         if (result.isSuccess()) {    
             // call successful    
         }    
});

API 參考: showLeaderboard(_:)

import HIVEService    

    ProviderApple.showLeaderboard() { result in    
         if result.isSuccess() {    
             // call successful    
         }    
}

API 參考: HIVEProviderApple ::showLeaderboard:

#import <HIVEService/HIVEService-Swift.h>    

    [HIVEProviderApple showLeaderboard: ^(HIVEResultAPI *result) {    
         if ([result isSuccess]) {    
             // call successful    
         }    
}];

在社交媒體上分享照片

用戶可以通過遊戲從設備的相冊導入照片,在 Facebook 上分享和發布照片。以下是示例代碼:

API 參考: SocialV4. sharePhoto

using hive;    

    SocialV4.ProviderType providerType = SocialV4.ProviderType.FACEBOOK;    

    SocialV4.sharePhoto(providerType, (ResultAPI result) => {    
         if (result.isSuccess()) {    
             // call successful    
         }    
});
#include "HiveSocialV4.h"

ESocialV4ProviderType ProviderType = ESocialV4ProviderType::FACEBOOK;
FHiveSocialV4::SharePhoto(ProviderType, FHiveSocialV4OnSharePhotoDelegate::CreateLambda([this](const FHiveResultAPI& Result) {
            if (Result.IsSuccess()) {
                // API call successful
        } 
}));

API 參考: SocialV4::sharePhoto

#include <HIVE_SDK_Plugin/HIVE_CPP.h>    
    using namespace std;    
    using namespace hive;    

    SocialV4::ProviderType providerType = SocialV4::ProviderType::FACEBOOK;    

    SocialV4::sharePhoto(providerType, [=](ResultAPI const & result) {    
         if (result.isSuccess()) {    
             // call successful    
         }    
});

API 參考: SocialV4.sharePhoto

import com.hive.SocialV4    
    import com.hive.ResultAPI    

    val providerType = SocialV4.ProviderType.FACEBOOK    

    SocialV4.sharePhoto(providerType, object : SocialV4.SocialV4SharePhotoListener {    
         override fun onShare(result: ResultAPI) {    
             if (result.isSuccess) {    
                 // call successful    
             }    
         }    
})

API 參考: SocialV4.INSTANCE. sharePhoto

import com.hive.SocialV4;    
    import com.hive.ResultAPI;    

    SocialV4.ProviderType providerType = SocialV4.ProviderType.FACEBOOK;    

    SocialV4.INSTANCE.sharePhoto(providerType, result -> {    
         if (result.isSuccess()) {    
             // call successful    
         }    
});

API 參考: SocialV4Interface.sharePhoto

import HIVEService    

    let providerType: SocialProviderType = .Facebook    

    SocialV4Interface.sharePhoto(providerType) { result in    
         if result.isSuccess() {    
             // call successful    
         }    
}

API 參考: HIVESocialV4 sharePhoto

#import <HIVEService/HIVEService-Swift.h>    

    HIVESocialProviderType providerType = HIVESocialProviderTypeFacebook;    

    [HIVESocialV4 sharePhoto: providerType handler: ^(HIVEResultAPI *result) {    
         if ([result isSuccess]) {    
             // call successful    
         }    
}];

使用社群登入自動登入電腦遊戲

當您在社區網站上點擊「在PC上播放」按鈕時,PC遊戲將通過Crossplay Launcher啟動。

此時,PC遊戲使用社區的「登錄令牌值」自動登錄。

Warning

**自動登入PC遊戲的社群登入**功能僅在Hive SDK v4 24.0.0及更高版本的Windows版本上運作。

Steam 隱式登入 (Unity Windows)

從 Hive SDK v4 Unity Windows 24.2.0 開始,Steam 隱式登錄已被支持。如果您選擇使用隱式登錄,您必須使用 AuthV4.Helper.signIn,而不能使用 AuthV4.signIn(AUTO,...)。由於這是一種隱式登錄,應用用戶在安裝遊戲後僅需登錄一次 Steam。在使用 Steam 隱式登錄時,您必須在應用刪除時實現刪除存儲 SDK 配置數據的 propFolder 文件夾。