ti.webdialog
Use the SFSafariViewController (iOS) and Chrome Pages (Android) in Titanium.
Install
A module is a zip you unpack in your project. There is no installer command yet - a ti module install is planned but does not exist today, so the steps below are the ones that work.
1. Download the release archive
2. Unpack it at your project root
cd /path/to/your-project unzip ~/Downloads/ti.webdialog-iphone-4.0.0.zipThe archive already contains the full path, so it lands in place:
- modules/iphone/ti.webdialog/4.0.0/
3. Add it to
tiapp.xml<modules> <module platform="iphone" version="4.0.0">ti.webdialog</module> </modules>The
platformattribute is the packager’s name for the platform, which isiphonefor iOS - the same word the archive uses in its own path.4. Require it from your app
const mod = require('ti.webdialog');
Manifest
iOS 4.0.0
- Minimum SDK
- 12.0.0
- Module API version
- 2
- Architectures
- arm64, x86_64
- GUID
- 1f19cce1-0ad7-4e25-ab3b-0666f54a0a49
- Author
- Hans Knoechel
- License
- Apache 2.0
- Copyright
- Copyright (c) 2017-present by TiDev
- Mac Catalyst
- not supported
API reference
Compiled from tidev/titanium-web-dialog@4.0.0 (96ff666).
Modules.WebDialog
Extends Titanium.Module
Allows a Titanium application to use the Safari Controller (iOS) and Chrome Tabs (Android) to create an embedded browser.
The WebDialog module provides Titanium access to the native SFSafariViewController (iOS) and ChromeTabs (Android).
This enables you to deliver interactive web content in your app just like the built-in browser, including the native UI elements already
familiar to your users.
Requirements
The WebDialog module is available with the Titanium SDK starting with Release 7.1.0. This module only works with devices running iOS 9 / Android 4.1 and later. Please make sure you have at least Xcode 7 to build to the required iOS sources.
Getting Started
Add the module as a dependency to your application by adding a <module> item to the
[modules](api:Modules) element of your tiapp.xml file:
<ti:app>
<!-- ... -->
[modules](api:Modules)
<module platform="iphone">ti.webdialog</module>
</modules>
<!-- ... -->
</ti:app>
Use require() to access the module from JavaScript:
var dialog = require('ti.webdialog');
The dialog variable is a reference to the module. Make API calls using this reference:
if (dialog.isSupported()) {
dialog.open({
url: 'https://titaniumsdk.com'
});
}
Sample Application
The module contains a sample application in the
<TITANIUM_SDK_HOME>/modules/iphone/ti.webdialog/<VERSION>/example/ folder.
Properties 3
Button style used to display a localized "Cancel" button.
Use with the dismissButtonStyle property in Modules.WebDialog.open.
Button style used to display a localized "Close" button.
Use with the dismissButtonStyle property in Modules.WebDialog.open.
Button style used to display a localized "Done" button.
Use with the dismissButtonStyle property in Modules.WebDialog.open.
Methods 5
Programmatically closes the web dialog.
var dialog = require('ti.webdialog');
if (dialog.isOpen()) {
dialog.close();
}
Creates and returns an instance of Modules.WebDialog.AuthenticationSession.
| Parameters | Type | Description |
|---|---|---|
| parameters? | Dictionary<Modules.WebDialog.AuthenticationSession> | Properties to set on a new object, including any defined by Modules.WebDialog.AuthenticationSession except those marked not-creation or read-only. |
isOpen
iPhoneiPadIndicates if the web dialog is open.
Indicates if the web dialog is supported.
Opens the web dialog with the options provided.
var dialog = require('ti.webdialog');
if (dialog.isSupported()) {
dialog.open({
url: 'https://titaniumsdk.com',
tintColor: 'red'
});
}
| Parameters | Type | Description |
|---|---|---|
| params | WebDialogOpenParams | Dictionary used to configure the web dialog. 7 fields
|
Events 4
close
iPhoneiPadThe close event is fired when the web dialog is closed by the user or programmatically.
| Event properties | Type | Description |
|---|---|---|
| url | String | The URL provided when opening the web dialog. |
load
iPhoneiPadFired when the initial URL load is complete.
This event is invoked when the erb dialog completes the loading of the URL that you pass to it's initializer. It is not invoked for any subsequent page loads in the same web dialog instance.
| Event properties | Type | Description |
|---|---|---|
| url | String | The URL provided when opening the web dialog. |
| success | Boolean | Returns |
open
iPhoneiPadThe open event is fired after the web dialog has opened.
| Event properties | Type | Description |
|---|---|---|
| url | String | The URL provided when opening the web dialog. |
redirect
iPhoneiPadFired when the browser is redirected to another URL before the first page load finishes.
| Event properties | Type | Description |
|---|---|---|
| url | String | The URL provided when opening the web dialog. |
Modules.WebDialog.AuthenticationSession
Extends Titanium.Proxy
Authenticate a user with a web service, even if the web service is run by a third party.
The AuthenticationSession puts the user in control of whether they want to use
their existing logged-in session from Safari. The app provides a URL that points
to the authentication webpage. The page will be loaded in a secure view controller.
From the webpage, the user can authenticate herself and grant access to the app.
On completion, the service will send a callback URL with an authentication token,
and this URL will be passed to the app by the callback.
The callback URL usually has a custom URL scheme. For the app to receive the
callback URL, it needs to either register the custom URL scheme in its Info.plist,
or set the scheme to scheme argument in the initializer.
If the user has already logged into the web service in Safari or other apps via
the AuthenticationSession, it is possible to share the existing login information.
An alert will be presented to get the user's consent for sharing their existing login
information. If the user cancels the alert, the session will be canceled, and
the callback will be called.
If the user taps Cancel when showing the login webpage for the web service, the session will be canceled, and the callback will be called as well.
The app can cancel the session by calling cancel(). This will also dismiss
the window that is showing the web service's login page.
Requirements
The AuthenticationSession API is available with the Titanium SDK starting with Release 7.1.0. This module only works with devices running iOS 11.0 and later. Please make sure you have at least Xcode 9 to build to the required sources.
Getting Started
Create a new authentication session by providing a url and scheme, create an event-listener and start:
var WebDialog = require('ti.webdialog');
var authSession = WebDialog.createAuthenticationSession({
url: 'https://example.com/oauth?callbackURL=myapp://',
scheme: 'myapp://'
});
authSession.addEventListener('callback', function(e) {
if (!e.success) {
Ti.API.error('Error authenticating: ' + e.error);
return;
}
Ti.API.info('Callback URL: ' + e.callbackURL);
});
authSession.start(); // Or cancel() to cancel it manually.
Properties 2
Methods 2
Cancel an authentication-session.
If the view controller is already presented to load the webpage for authentication, it will be dismissed. Calling cancel on an already canceled session will have no effect.
Starts the AuthenticationSession instance after it is instantiated.
The start method can only be called once for an AuthenticationSession
instance. This also means calling start on a canceled session will fail.
Returns true if the session starts successfully.
Events 1
The callback which is called when the session is completed successfully or canceled by user.
| Event properties | Type | Description |
|---|---|---|
| error | String | The error-message returned in case something went wrong. |
| callbackURL | String | The callback-URL returned in case the OAuth-flow succeeded. |
AuthenticationSessionCallback
The callback which is called when the session is completed successfully or canceled by user.
Properties 3
callbackURL
StringThe callback-url passed if no error occured, undefined otherwise.
error
StringThe error returned if the authentication-session failed, undefined otherwise.
success
BooleanReturns true if the authentication-session completed successfully, false otherwise.