Overview
KlugPush brings remote push notifications to AIR apps on macOS. It registers the app with Apple's push notification service, gives you the device token for your server, and delivers incoming notifications to ActionScript.
On macOS a user who once declined notifications is not asked again. KlugPush therefore reports the current permission status at any time and opens the Notifications page in System Settings, so users can turn notifications on later.
KlugPush is in daily use in the PetCam App for the Mac, our proof of concept.
Features
- Asks for permission and registers for remote notifications
- Device token for your server, as soon as registration finishes
- Incoming notifications delivered to ActionScript as JSON
- Live permission status: not yet decided, denied or allowed
- Opens System Settings directly at Notifications
- Sent straight through Apple's push service, no extra push provider needed
Supported platforms
On other platforms isSupported returns false, so the same code can stay in a cross-platform app.
Getting started
Add the extension to your application descriptor:
<extensions>
<extensionID>com.klug.push.Push</extensionID>
</extensions>
The app must be signed with the push notifications entitlement and a provisioning profile that includes the Push Notifications capability.
Quick example
import com.klug.push.Push; var push:Push = Push.getInstance(); if ( push.isSupported ) { push.register( function( token:String ):void { sendTokenToServer( token ); }, function( error:String ):void { trace( error ); }, function( json:String ):void { showNotification( json ); } ); }
push.refreshStatus( function( status:int ):void { if ( status == Push.STATUS_DENIED ) push.openSettings(); // let the user turn notifications on } );
API overview
| Push.getInstance() | Returns the single instance. |
| isSupported | True on macOS. |
| register(onToken, onError, onNotification) | Asks for permission and registers for remote notifications. |
| token | The last device token, or null until registration finishes. |
| authStatus | The last known permission status. |
| refreshStatus(onStatus) | Reads the current permission status. |
| openSettings() | Opens System Settings at Notifications. |
| STATUS_NOT_DETERMINED, STATUS_DENIED, STATUS_AUTHORIZED | Permission status values. |
| StatusEvent: token, error, notification | The same results as events, for listeners. |
Requirements
| AIR SDK | 51.x (HARMAN) |
| macOS | macOS 11 or later |
| Signing | Push notifications entitlement and a matching provisioning profile |
| Server | Sends notifications through Apple's push service |