Socialid.webPush.init

From Social ID Developers
Revision as of 19:38, 15 October 2020 by Renato.neves (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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.webPush.init(appId, applicationKey, 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.
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.
subscribeHandler optional A callback function to handle the subscribe response. See Subscribe API for more details.
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.

 var handler = function(response) {
   if (response.status == "success") {
     alert("You have been subscribed successfully!");
   } else {
     alert("Could not subscribe you.");
   }
 }
 socialid.webPush.init(1, "BLBfmHjQRScxP-EoKX_5O-mxMItGmuRRZLj28HBuO18ddUmzRd_75SIgb4u2XjNJjM5p85JQVl2l2vieCh-7S8Q=", {
   subscribeHandler: handler
 });

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.

 socialid.webPush.init(1, "BLBfmHjQRScxP-EoKX_5O-mxMItGmuRRZLj28HBuO18ddUmzRd_75SIgb4u2XjNJjM5p85JQVl2l2vieCh-7S8Q=", {
   subscribeOnInit: false
 });

This example specifies a custom path for the service worker script.

 socialid.webPush.init(1, "BLBfmHjQRScxP-EoKX_5O-mxMItGmuRRZLj28HBuO18ddUmzRd_75SIgb4u2XjNJjM5p85JQVl2l2vieCh-7S8Q=", {
   serviceWorkerPath: "/scripts/serviceWorker.js"
 });
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox