跳转到内容

渠道特性(Cocos)

不同渠道允许的能力不同:有的能打开外链,有的不能;有的支持浏览器导航,有的把玩家锁在游戏里。在写依赖这些能力的 UI 之前,先读这些标志。

const chars = FRVRSDK.instance.getChannelCharacteristics();
// 一个对象,字段是布尔风格的值,描述渠道的权限。

if (FRVRSDK.instance.allowsExternalLinks()) {
  // 可以放心展示"隐私政策"、"关于"等外链。
  showExternalLinks();
}

if (FRVRSDK.instance.allowsNavigation()) {
  // 可以放心 push URL 状态 / 使用浏览器后退按钮。
  enableLocationRouting();
}
if (FRVRSDK.instance.allowsExternalLinks()) {
  this.showPrivacyLink();
  this.showCreditsLink();
} else {
  // 渠道处于沙盒中 —— 用一个游戏内隐私页代替外链。
  this.showInGamePrivacyScreen();
}

常见的”不允许外链”渠道:Facebook Instant、部分云游戏平台。常见的”允许外链”渠道:Web 门户、原生封装。

if (FRVRSDK.instance.allowsNavigation()) {
  history.pushState({ scene: 'shop' }, '', '/shop');
} else {
  // 留在当前场景内;不要碰 history。
  goToScene('shop');
}

写死一个”隐私政策”按钮、然后在一半渠道里悄悄失效,比让 UI 随渠道感知差很多。这些标志让你能用同一份构建跑遍所有渠道,在运行时自动适配。