呼叫網頁內容
網頁內容呼叫是一項功能,允許您通過調用遊戲內瀏覽器、網頁視圖或外部瀏覽器直接查看網頁內容。
用戶可以通過調用適合每個遊戲環境的遊戲內瀏覽器或網頁視圖來查看網頁內容,而無需離開遊戲。此外,遊戲可以靈活地利用各種網頁內容,提升用戶體驗。
根據遊戲環境,可以使用以下介面實現網頁內容調用:
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 调用成功
}
});
#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 呼叫成功
}
}));
#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 调用成功
}
});
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 呼叫成功
});
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 呼叫成功
}
};
#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 调用成功
}
}];
在遊戲內網頁視圖中打開¶
在遊戲中通過打開網頁視圖來調用網頁內容。
設定功能¶
「在遊戲內網頁視圖中打開」是使用InAppWebViewParam參數實現的。InAppWebViewParam對象提供的useUserSession參數可以將應用內登錄會話發送到網頁視圖,postData可以發送應用開發者所需的額外信息。
InAppWebViewParam 參數特性、默認設置和要求如下:
| 功能 | 描述 | 默認值 | 必需 |
|---|---|---|---|
| postData | 包含應用開發者要發送的附加信息的數據。當有附加信息需要在網頁視圖中顯示時使用。 | null | X |
| useUserSession | 包含登錄會話信息。在JSON格式的postData中包含player_id和player_token。 | false | X |
| useGameWindow | 僅限Android的功能,在當前窗口中顯示WebView。未暫停,並且忽略HiveTheme和HiveOrientation設置。 | false | X |
Warning
使用useUserSession时,postData必须为JSON格式。
範例代碼¶
InAppWebViewParam '使用網頁視圖打開' 的範例代碼如下:
#include "HivePlatformHelper.h"
FString URL = TEXT("https://developers.withhive.com/");
FHiveInAppWebViewParam Param(URL);
Param.UseUserSession = true;
Param.UseGameWindow = true;
FHivePlatformHelper::ShowInAppWebView(Param, FHivePlatformHelperOnShowInAppWebViewDelegate::CreateLambda([this](const FHiveResultAPI& Result) {
if (Result.IsSuccess()) {
// API call successful
}
}));
#include <HIVE_SDK_Plugin/HIVE_CPP.h>
using namespace std;
using namespace hive;
InAppWebViewParam *param = new InAppWebViewParam("https://developers.withhive.com/");
param->useUserSession = true;
param->useGameWindow = 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)
.setUseGameWindow(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)
.setUseGameWindow(true)
.build()
PlatformHelper.showInAppWebView(param, object : PlatformHelper.InAppWebViewListener {
override fun onInAppWebView(result: ResultAPI) {
if (result.isSuccess) {
// API 呼叫成功
}
}
})
#import <HIVEService/HIVEService-Swift.h>
HiveInAppWebViewParamBuilder *builder = [[HiveInAppWebViewParamBuilder alloc] initWithUrl: @"https://developers.withhive.com/"];
HiveInAppWebViewParam *inAppWebViewParam = [[[builder setUseUserSession: @YES]
setUseGameWindow: @YES]
build];
[HIVEPlatformHelper showInAppWebView: inAppWebViewParam handler: ^(HIVEResultAPI *result) {
if ([result isSuccess]) {
// API call successful
}
}];
使用外部瀏覽器開啟¶
透過從遊戲連接一個單獨的外部瀏覽器來調用網頁內容。
Note
'使用外部瀏覽器開啟' 僅在 PC 遊戲環境中支援,並從 Hive SDK v4 Windows 25.1.0 及以上版本提供。
配置功能¶
OpenBrowserParam 用於調用外部瀏覽器,您還可以額外設置 useIncognitoMode 選項以使用隱身模式。
'使用外部瀏覽器打開' 是使用 OpenBrowserParam 參數實現的。您可以使用 useIncognitoMode 參數設置隱身模式選項。
OpenBrowserParam 參數的特性和要求如下:
| 功能 | 描述 | 必需 |
|---|---|---|
| url | 用於外部瀏覽器調用的URL信息 | O |
| useIncognitoMode | * true: 調用隱身模式瀏覽器 * false: 調用正常模式瀏覽器 | O |
示例代碼¶
OpenBrowserParam '使用外部瀏覽器打開' 的範例代碼如下: