native.showPopup() — Safari 视图

类型 函数
native.*
返回值
版本 版本 2024.3703
关键词 native, showPopup, safari, safariView, webView

概述

显示 Safari 视图弹出窗口,该窗口对应于 iOS 9 中引入的 SFSafariViewControlleriOS 9(参考)。与 native.newWebView() 相比,Safari 视图与原生 iOS Safari 应用共享 Cookie、会话和其他浏览器数据。

注意事项

语法

native.showPopup( name, options )
name (必需)

字符串. 要显示的弹出窗口的字符串名称。对于 Safari 视图插件,请使用 "safariView"

options (必需)

. 指定弹出窗口可选属性的表 — 有关详细信息,请参阅下一节。

选项参考

url (必需)

字符串. 网页的 URL。该 URL 必须以 http://https:// 开头。

animated (可选)

布尔值. 如果为 true,则控制器滑入;否则立即显示。

entersReaderIfAvailable (可选)

布尔值. 如果为 true,则在网页可用时自动进入阅读器模式。

listener (可选)

监听器. 支持基本 弹出事件 的监听器。对于该事件,event.action (字符串) 可以是以下值之一

  • "loaded" — 初始加载已完成。
  • "failed" — 表示加载 URL 时出错;Safari 视图保持打开状态。
  • "done" — 表示用户按下“完成”按钮,Safari 视图已关闭。

示例

local function safariListener( event )
    if ( event.action == "failed" ) then
        print( "Error loading the URL" )
    elseif ( event.action == "loaded" ) then
        print( "Page loaded!" )
    elseif ( event.action == "done" ) then
        print( "Safari view closed" )
    end
end

local popupOptions =
{
    url = "http://solar2d.cn",
    animated = true,
    entersReaderIfAvailable = true,
    listener = safariListener
}

-- Check if the Safari View is available
local safariViewAvailable = native.canShowPopup( "safariView" )

if safariViewAvailable then
    -- Show the Safari View
    native.showPopup( "safariView", popupOptions )
end