调用网页内容
网页内容调用是一项功能,允许您通过调用游戏内浏览器、网页视图或外部浏览器直接从游戏中查看网页内容。
用户可以通过调用适合每个游戏环境的游戏内浏览器或网页视图来查看网页内容,而无需离开游戏。此外,游戏可以灵活地利用各种网页内容,从而增强用户体验。
可以根据游戏环境通过以下接口实现网页内容调用:
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 '使用WebView打开'的示例代码如下:
#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调用成功
}
});
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 调用成功
}
}];
使用外部浏览器打开¶
通过从游戏中连接一个单独的外部浏览器来调用网页内容。
Note
“使用外部浏览器打开”仅在PC游戏环境中支持,并从Hive SDK v4 Windows 25.1.0及以上版本提供。
配置功能¶
OpenBrowserParam 用于调用外部浏览器,您还可以额外设置 useIncognitoMode 选项以使用隐身模式。
“使用外部浏览器打开”是通过OpenBrowserParam参数实现的。您可以使用useIncognitoMode参数设置隐身模式选项。
OpenBrowserParam 参数特性和要求如下:
| 特性 | 描述 | 必需 |
|---|---|---|
| url | 用于外部浏览器调用的URL信息 | O |
| useIncognitoMode | * true: 调用隐身模式浏览器 * false: 调用正常模式浏览器 | O |
示例代码¶
OpenBrowserParam '使用外部浏览器打开' 的示例代码如下: