1.0.24 • Published 1 year ago

hpub2 v1.0.24

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

MagLoft HPUB2 SDK

API Documentation for MagLoft Mobile Apps HPUB2 JavaScript Context

Installation

  • Download hpub2.js or install via npm install hpub2
  • Insert the script before the closing </body> tag

Usage

  • The MagLoft Native App will automatically initialize the SDK on load.
  • The HPUB2 API is exposed on window.MagloftApi
  • The current device / user context can be accessed at window.MagloftApi.context
  • API Methods are documented here

Examples

Open a URL in the device browser

MagloftApi.openUrl({ url: 'https://www.magloft.com/', target: '_blank' })

Track an Event using Firebase Analytics

MagloftApi.trackEvent({ name: 'purchase', parameters: { sku: 'ML123', price: 99 } })

Open the top navigation bar

MagloftApi.toggleNavigator({ active: true })

Share a URL using the native share dialog

MagloftApi.shareUrl({ url: 'https://www.magloft.com/' })

Share the current HPUB issue using the native share dialog

MagloftApi.shareIssue()

Close the current HPUB issue and return to the shelf

MagloftApi.close()

Trigger the native login flow

This will trigger the native Login Dialog. Will return the logged in reader (if successful), or undefined (if failed)

MagloftApi.login().then((reader) => {
  alert(reader.email)
})

Request Push Permissions

This will trigger the native Push Notification screen, prompting users to either allow or block notifications. Will return the new pushToken (if allowed), or undefined (if blocked)

MagloftApi.requestPushPermissions().then((pushToken) => {
  alert(pushToken)
})

Schedule Push Notifications

Schedule up to 1000 messages for the current user. The user needs to be logged in and must have accepted push notification permissions.

MagloftApi.schedulePushMessages([{
  title: 'Message 1',
  body: 'Message Body'
  deliveryDate: 1663910000, // UNIX Timestamp
  data: { key: 'value' } // Any Record<string, string>
}, {
  title: 'Message 2',
  body: 'Message Body'
  deliveryDate: 1663910000, // UNIX Timestamp
  data: { key: 'value' } // Any Record<string, string>
}]).then((scheduledCount) => {
  alert(`Scheduled ${scheduledCount} messages`)
})

Clear Push Notifications

Clear all scheduled push messages for the current user. The user needs to be logged in and must have accepted push notification permissions.

MagloftApi.clearPushMessages().then(() => {
  alert(`Cleared all push messages`)
})
1.0.24

1 year ago

1.0.22

1 year ago

1.0.23

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago