hpub2
v1.0.24
Published
> API Documentation for MagLoft Mobile Apps HPUB2 JavaScript Context
Downloads
6
Readme
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), orundefined
(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`)
})