【问题标题】:webkit.messageHandlers not working on iPadwebkit.messageHandlers 在 iPad 上不起作用
【发布时间】:2021-12-30 05:53:22
【问题描述】:

总结问题

我在 App Store 上注册了我的 iOS 应用,但它被拒绝了。 基本上它在 iPhone 上运行良好。 但是我听说有一个功能在 iPad 上不能正常工作。 该应用程序部分具有 web 视图。 在我的测试中,它不适用于 iPad(15.2、15.1)。它也可能不适用于旧版本。 从 webview 调用 webkit.messageHandlers 不起作用

描述你的尝试

在项目开始时,我们使用现代 JavaScript 语法进行开发。 但是,iOS 14.2 版本中的导入/导出语法导致问题并修复了与 webpack 的代码兼容性问题。 我没有尝试过该解决方案,因为我不明白为什么 iPhone 和 iPad 的行为不同。

我的代码

import { checkAndroid, checkIos } from "../../js/utils/index.js";

const step1El = document.querySelector("#step1");
const step2El = document.querySelector("#step2");
const btnEl = document.querySelector("button");

btnEl.onclick = function () {
  if (!step1El.checked)
    return alert("블록체인 간편인증 서비스 이용약관에 동의해주세요");
  if (!step2El.checked)
    return alert("개인정보 수집 및 이용 동의서에 동의해주세요");

  if (checkAndroid()) window.Android.agree();
  if (checkIos()) webkit.messageHandlers.agree.postMessage(""); // not working on iPad
};

document.querySelector(".tos_btn").onclick = () => {
  if (checkAndroid()) window.Android.goTermsConditions(true);
  if (checkIos()) webkit.messageHandlers.goTermsConditions.postMessage(true); // not working on iPad
};
document.querySelector(".policy_btn").onclick = () => {
  if (checkAndroid()) window.Android.goCollectionAgreement();
  if (checkIos()) webkit.messageHandlers.goCollectionAgreement.postMessage(""); // not working on iPad
};

【问题讨论】:

    标签: javascript ios webview app-store


    【解决方案1】:

    我解决了这个问题。

    问题是我的错误。

    问题出在 checkIos 函数中

    之前

    export function checkIos() {
      const userAgent = window.navigator.userAgent.toLowerCase();
      if (userAgent.indexOf("iphone") > -1)
        return true;
      return false;
    }
    

    之后

    export function checkIos() {
      const userAgent = window.navigator.userAgent.toLowerCase();
      if (userAgent.indexOf("iphone") > -1 || userAgent.indexOf("ipad") > -1)
        return true;
      return false;
    }
    

    【讨论】:

      猜你喜欢
      • 2015-11-06
      • 2011-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-07
      相关资源
      最近更新 更多