Socialid.webPush.init
(Difference between revisions)
(Created page with "== Description == Initializes the API to be used by a Social Login application. It's required to call this function to unlock the other Web Push APIs. == Usage == sociali...") |
(→Example) |
||
Line 51: | Line 51: | ||
}); | }); | ||
− | This example initializes the Web Push API with | + | This example initializes the Web Push API with ''subscribeOnInit'' option disabled. Notice that you'll have to call the [[socialid.webPush.subscribe | Subscribe API]] explicitly to perform the subscription. Use this option to have more control on when to ask the user for Web Push Notification permission. |
It also defines a custom path for the service worker script. | It also defines a custom path for the service worker script. |
Revision as of 21:23, 16 January 2017
Contents |
Description
Initializes the API to be used by a Social Login application. It's required to call this function to unlock the other Web Push APIs.
Usage
socialid.login.init(appId, applicationKey, handler, options)
Parameters
appId | required | The identifier number of the Social Login application. The same user for the Social Login API. | applicationKey | required | The VAPID public key for Web Push integration. It can be found in the API Settings of your Login App. Please contact us if you already own a VAPID key pair and would like to use it instead. | handler | optional | A callback function to handle the subscribe response. See Subscribe API for more details. | options | optional | A Javascript object containing additional parameters. | subscribeOnInit | optional | A boolean value to inform whether the Subscribe API should be called right after initialization or not. Default: true. | serviceWorkerPath | optional | The relative path for the service worker javascript file that should be hosted in the client website. Default: "/sw.js". |
---|
Example
This example initializes the Web Push API to be used by the application with id "1" with its corresponding application key.
socialid.webPush.init(1, "BLBfmHjQRScxP-EoKX_5O-mxMItGmuRRZLj28HBuO18ddUmzRd_75SIgb4u2XjNJjM5p85JQVl2l2vieCh-7S8Q=");
This example initializes the Web Push API with a handler for the Subscribe API.
socialid.webPush.init(1, "BLBfmHjQRScxP-EoKX_5O-mxMItGmuRRZLj28HBuO18ddUmzRd_75SIgb4u2XjNJjM5p85JQVl2l2vieCh-7S8Q=", function(response) { if (response.status == "success") { alert("You have been subscribed successfully!"); } else { alert("Could not subscribe you."); } });
This example initializes the Web Push API with subscribeOnInit option disabled. Notice that you'll have to call the Subscribe API explicitly to perform the subscription. Use this option to have more control on when to ask the user for Web Push Notification permission.
It also defines a custom path for the service worker script.
socialid.webPush.init(1, "BLBfmHjQRScxP-EoKX_5O-mxMItGmuRRZLj28HBuO18ddUmzRd_75SIgb4u2XjNJjM5p85JQVl2l2vieCh-7S8Q=", null, { subscribeOnInit: false, serviceWorkerPath: "/scripts/serviceWorker.js" });