跳轉至

呼叫網頁內容

網頁內容呼叫是一項功能,允許您通過調用遊戲內瀏覽器和網頁視圖或外部瀏覽器直接檢查網頁內容。

用戶可以根據每個遊戲環境通過調用遊戲內瀏覽器或網頁視圖來檢查網頁內容,而無需離開遊戲。此外,它還允許在遊戲中靈活使用各種網頁內容,增強用戶體驗。

根據遊戲環境,可以使用以下介面實現網頁內容調用。

Note

有關「在遊戲中打開瀏覽器」的更多信息,請參閱 Android 的 自定義標籤 和 iOS 的 SFSafariViewController 文檔。

在遊戲內開啟瀏覽器

透過遊戲內瀏覽器調用外部內容,而無需打開單獨的瀏覽器。

Note

「在遊戲內瀏覽器中開啟」目前僅在手機遊戲環境中受支持。

設定功能

'在遊戲內開啟瀏覽器'是使用'InAppBrowserParam'參數實現的。

InAppBrowserParam 可以設置的參數及其默認值如下。

功能 內容 預設設定值
導航顏色 指定頂部導航區域的顏色。 操作系統預設顏色
按鈕顏色(僅限 iOS) 指定頂部導航區域的按鈕顏色。 操作系統預設顏色
隱藏網址列 當發生滾動事件時,隱藏頂部網址顯示區域。 true
自動重定向到外部瀏覽器(僅限 Android) 如果設備的預設應用程式中設置的瀏覽器應用不受支持,則自動支持連接到外部瀏覽器。 true

示例代码

“使用 InAppBrowserParam 打开游戏内浏览器”的示例代码如下。

using hive;

InAppBrowserParam param = new InAppBrowserParam.Builder("https://developers.withhive.com/")
                                                .setNavigationColor("#3891f0")
                                                .setButtonColor("#ffffff")
                                                .setUrlBarHiding(true)
                                                .setAutoRedirectToExternalBrowser(true)
                                                .build();

    PlatformHelper.showInAppBrowser(param, (ResultAPI result) => {
            if (result.isSuccess()) {
                    // API call successful
            }
    });
#include "HivePlatformHelper.h"

FString URL = TEXT("https://developers.withhive.com/");
FHiveInAppBrowserParam Param(URL);
Param.NavigationColor = TEXT("3891f0");
Param.ButtonColor = TEXT("#FFFFFF");
Param.UrlBarHiding = true;
Param.AutoRedirectToExternalBrowser = true;

FHivePlatformHelper::ShowInAppBrowser(Param, FHivePlatformHelperOnShowInAppBrowserDelegate::CreateLambda([this](const FHiveResultAPI& Result) {
        if (Result.IsSuccess()) {
                // API call succeeded
        }
}));
    #include <HIVE_SDK_Plugin/HIVE_CPP.h>
    using namespace std;
    using namespace hive;

    InAppBrowserParam *param = new InAppBrowserParam("https://developers.withhive.com/");
    param->navigationColor = "3891f0";
    param->buttonColor = "#ffffff";
    param->urlBarHiding = true;
    param->autoRedirectToExternalBrowser = true;

    PlatformHelper::showInAppBrowser(*param, [=](ResultAPI const & result) {
            if (result.isSuccess()) {
                    // API call successful
            }
    });
    import com.hive.PlatformHelper;
    import com.hive.ResultAPI;

    PlatformHelper.InAppBrowserParam param = new PlatformHelper.InAppBrowserParam.Builder("https://developers.withhive.com/")
                                    .setNavigationColor("#3891f0")
                                    .setUrlBarHiding(true)
                                    .setAutoRedirectToExternalBrowser(true)
                                    .build();

    PlatformHelper.showInAppBrowser(param, result -> {
            if (result.isSuccess()) {
                    // API call successful
            }

    });
import com.hive.PlatformHelper;
import com.hive.ResultAPI;

val param = PlatformHelper.InAppBrowserParam.Builder("https://developers.withhive.com/")
                                        .setNavigationColor("#3891f0")
                                        .setUrlBarHiding(true)
                                        .setAutoRedirectToExternalBrowser(true)
                                        .build()

PlatformHelper.showInAppBrowser(param, object : PlatformHelper.InAppBrowserListener {
        override fun onInAppBrowser(result: ResultAPI) {
                if (result.isSuccess) {
                        // API 呼叫成功
                }
        }
})
import HIVEService

let inAppBrowserParam = InAppBrowserParam.Builder(url: "https://developers.withhive.com/")
                                                .setNavigationColor("#3891f0")
                                                .setButtonColor("#ffffff")
                                                .setUrlBarHiding(true)
                                                .setAutoRedirectToExternalBrowserbuild(true)
                                                .build()

PlatformHelperInterface.showInAppBrowser(inAppBrowserParam) { resultAPI in
    if result.isSuccess() {
                // API call successful
        }
};
#import <HIVEService/HIVEService-Swift.h>

HiveInAppBrowserParamBuilder *builder = [[HiveInAppBrowserParamBuilder alloc] initWithUrl: @"https://developers.withhive.com/"];
HiveInAppBrowserParam *inAppBrowserParam = [[[[[builder setNavigationColor: @"#3891f0"]
                                                        setButtonColor: @"#ffffff"]
                                                        setUrlBarHiding: @YES]
                                                        setAutoRedirectToExternalBrowser: @YES]
                                                        build];

[HIVEPlatformHelper showInAppBrowser: inAppBrowserParam handler: ^(HIVEResultAPI *result) {
        if ([result isSuccess]) {
                // API call succeeded
        }
}];


在應用內網頁視圖中打開

在遊戲中使用網頁視圖打開網絡內容。

設定功能

在遊戲內實現的「在網頁視圖中打開」是使用InAppWebViewParam參數來實現的。InAppWebViewParam對象提供的useUserSession參數可以將應用內登錄會話發送到網頁視圖,並且應用開發者希望發送的其他信息可以通過postData發送。

InAppWebViewParam 可以設定的參數及其預設值如下。

功能 描述 默認值 必需
useUserSession 這是應用內的登錄會話信息。它包含包含player_idplayer_token的JSON數據。 false X
postData 這是包含應用開發者要發送的附加信息的數據。當您想在網頁視圖中顯示附加信息時使用。 null X
Warning

使用 useUserSession 時,postData 必須為 JSON 格式。

示例代码

InAppBrowserParam 用於「在 WebView 中打開」的示例代碼如下。

using hive;

InAppWebViewParam param = new InAppWebViewParam.Builder("https://developers.withhive.com/")
                                                .setUseUserSession(true)
                                                .build();

    PlatformHelper.showInAppWebView(param, (ResultAPI result) => {
            if (result.isSuccess()) {
                    // API call succeeded
            }
    });
#include "HivePlatformHelper.h"

FString URL = TEXT("https://developers.withhive.com/");
FHiveInAppWebViewParam Param(URL);
Param.UseUserSession = true;

FHivePlatformHelper::ShowInAppWebView(Param, FHivePlatformHelperOnShowInAppWebViewDelegate::CreateLambda([this](const FHiveResultAPI& Result) {
        if (Result.IsSuccess()) {
                // API call succeeded
        }
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace std;
using namespace hive;

InAppWebViewParam *param = new InAppWebViewParam("https://developers.withhive.com/");
param->useUserSession = true;

PlatformHelper::showInAppWebView(*param, [=](ResultAPI const & result) {
        if (result.isSuccess()) {
                // API call successful
        }
});
import com.hive.PlatformHelper;
import com.hive.ResultAPI;

PlatformHelper.InAppWebViewParam param = new PlatformHelper.InAppWebViewParam.Builder("https://developers.withhive.com/")
                                .setUseUserSession(true)
                                .build();

PlatformHelper.showInAppWebView(param, result -> {
        if (result.isSuccess()) {
                // API call successful
        }     
});
import com.hive.PlatformHelper;
import com.hive.ResultAPI;

val param = PlatformHelper.InAppWebViewParam.Builder("https://developers.withhive.com/")
                                        .setUseUserSession(true)
                                        .build()

PlatformHelper.showInAppWebView(param, object : PlatformHelper.InAppWebViewListener {
        override fun onInAppWebView(result: ResultAPI) {
                if (result.isSuccess) {
                        // API call successful
                }
        }
})
import HIVEService

let inAppWebViewParam = InAppWebViewParam.Builder(url: "https://developers.withhive.com/")
                                                .setUseUserSession(true)
                                                .build()

PlatformHelperInterface.showInAppWebView(inAppWebViewParam) { resultAPI in
    if result.isSuccess() {
                // API call successful
        }
};
#import <HIVEService/HIVEService-Swift.h>

HiveInAppWebViewParamBuilder *builder = [[HiveInAppWebViewParamBuilder alloc] initWithUrl: @"https://developers.withhive.com/"];
HiveInAppWebViewParam *inAppWebViewParam = [[builder setUseUserSession: @YES]
                                                        build];

[HIVEPlatformHelper showInAppWebView: inAppWebViewParam handler: ^(HIVEResultAPI *result) {
        if ([result isSuccess]) {
                // API 呼叫成功
        }
}];


在外部瀏覽器中打開

將外部瀏覽器連接到遊戲以調用網頁內容。

Note

'在外部瀏覽器中打開'僅在PC遊戲環境中受支持,從Hive SDK v4 Windows 25.1.0開始。

設定功能

您可以使用 OpenBrowserParam 呼叫外部瀏覽器,此外,您可以設置 useIncognitoMode 選項以啟用隱身模式。

「在外部瀏覽器中打開」是使用 OpenBrowserParam 參數實現的。您可以使用 useIncognitoMode 參數設置隱身模式選項。

OpenBrowserParam 可以設定的參數及其預設值如下。

功能 描述 必需
url 用於調用外部瀏覽器的URL信息 O
useIncognitoMode * true: 在隱身模式瀏覽器中調用
* false: 在正常模式瀏覽器中調用
O

示例代碼

OpenBrowserParam 用於「在外部瀏覽器中打開」的使用範例如下。

using hive;

OpenBrowserParam param = new OpenBrowserParam.Builder("https://developers.withhive.com/")
                                                .setUseIncognito(true)
                                                .build();

PlatformHelper.openBrowser(param);
#include "HivePlatformHelper.h"

FString URL = TEXT("https://developers.withhive.com/");
FHiveOpenBrowserParam Param(URL);
Param.useIncognitoMode = true;

FHivePlatformHelper::openBrowser(Param);
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace std;
using namespace hive;

OpenBrowserParam *param = new OpenBrowserParam("https://developers.withhive.com/");
param->useIncognitoMode = true;

PlatformHelper::openBrowser(*param);