WebViewGold 文档 · iOS
🇨🇳 中文
获取 WebViewGold

UUID API

通过附加到 WebView URL 或经由 JavaScript 获取的唯一 UUID 来识别应用安装。

The WebViewGold UUID API allows you to retrieve a non-personal, unique device ID (UUID - "Universally Unique Identifier"), which can uniquely identify an iOS device. This feature can be helpful for:

  • Storing user-specific settings on the server
  • Maintaining session states
  • Recalling saved data on the client side

Privacy Note: Ensure compliance with local and international privacy laws when using this feature, as it involves device identification.

How to Retrieve UUID:

To retrieve the UUID from your WebView-based app, use the following code:

<a href="get-uuid://">Get UUID</a>
<a href="#" onClick="alert(uuid);">Show UUID</a>
                    
  • Get UUID: Requests the UUID from WebViewGold.
  • Show UUID: Displays the UUID via an alert for easy testing.

Alternative Method: Append the UUID to the WebView URL

If you prefer to include the UUID in the URL parameters, enable the enhanceUrlUUID option in Config.swift by setting it to true. This will automatically append uuid=XYZ to your WebView URL on the first request, allowing you to access the UUID directly in your web content:

  • Example: If your WebView URL is https://www.example.org, it will be requested as https://www.example.org?uuid=XYZ.
  • Note: Only the initial URL request will include this GET parameter, so consider saving it in a session or cookie if you need to reference it later in the app.

Automatically Inject UUID into JavaScript:

To automatically make UUID (and other variables) available in JavaScript across all pages without modifying URLs, set autoInjectVariable to true in Config.swift. This allows you to access the UUID and other values directly within any page.

SDK 风格的实现说明

将此功能视为向 Web 层公开的原生能力:将生产网站或 PWA 作为唯一可信来源,然后使用文档中的 WebViewGold 配置标志、URL 命令和 JavaScript 桥接调用,仅在能够带来价值的地方启用原生 iOS 行为。这种方式让代码库易于维护,因为同一个 Web 应用只需极少的条件逻辑即可同时服务于浏览器、WebViewGold for iOS 以及其他 WebViewGold 平台。

为获得可靠的结果,建议优先使用 HTTPS 端点、稳定的路由名称、在界面中明确的成功/错误状态,以及封装原生调用的小型 JavaScript 辅助函数。例如,使用 jQuery Mobile、Lovable、Base44、Bolt、WordPress、Bubble、自定义 React/Vue/Angular 技术栈或静态 HTML 构建的 Web 应用,可以提供单个按钮或事件处理程序来触发原生 WebViewGold API,同时仍为浏览器提供优雅的回退方案。

  • 推荐的集成模式:检测应用上下文,调用 WebViewGold API,然后在原生回调或路由变更后更新 Web 界面。
  • 测试清单:在真机或打包构建上验证该功能,检查权限和商店审核文案,并确认仅使用浏览器的用户仍能获得有用的回退方案。
  • SEO 优势:让功能页面、路由标题和结构化内容在您的网站上保持可被索引,同时由 WebViewGold 为 iOS 用户提供原生应用外壳。

太忙了?我们替您搭建应用。

我们的团队为您配置、构建并提交 WebViewGold 应用——全程代劳、交付迅速、德国制造。

让我们搭建应用 →

在浏览器中构建

无需 Mac、无需 IDE:WebViewGold Cloud Builder 在线为您配置、构建并上传应用。

了解 Cloud Builder →