native.showPopup() — Safari View

Type function
Library native.*
Return value none
Revision Release 2024.3703
Keywords native, showPopup, safari, safariView, webView

Overview

Displays the Safari View popup which corresponds to the SFSafariViewController, introduced in iOS 9 (reference). In contrast to native.newWebView(), the Safari View shares cookies, sessions, and other browser data with the native iOS Safari app.

Gotchas

Syntax

native.showPopup( name, options )
name (required)

String. The string name of the popup to be shown. For the Safari View plugin, use "safariView".

options (required)

Table. A table that specifies the optional properties for the popup — see the next section for details.

Options Reference

url (required)

String. URL of the web page. This must start with http:// or https://.

animated (optional)

Boolean. If true, the controller slides in; otherwise it appears instantly.

entersReaderIfAvailable (optional)

Boolean. If true, Reader mode will be entered automatically when it is available for the web page.

listener (optional)

Listener. Listener which supports basic popup events. For the event, event.action (string) may be one of the following:

  • "loaded" — Initial loading is finished.
  • "failed" — Indicates there was an error while loading the URL; the Safari View remains open.
  • "done" — Indicates that the user pressed the "Done" button and the Safari View was closed.

Example

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 = "https://coronalabs.com",
    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