跳转至

调用网页内容

网页内容调用是一项功能,允许您通过调用游戏内浏览器和网页视图或外部浏览器直接在游戏中检查网页内容。

用户可以根据每个游戏环境通过调用游戏内浏览器或网页视图来检查网页内容,而无需离开游戏。此外,它还允许在游戏中灵活使用各种网页内容,从而增强用户体验。

根据游戏环境,可以使用以下接口实现网页内容调用。

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 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 调用成功
            }
    });
    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 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 调用成功
                }
        }
})
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);