A Flutter plugin to use push notification delivery service from PUSHY.
With this plugin, your Flutter app can receive and process push notifications on Android and iOS. Read Pushy SDK documentation to get good understanding about how it works.
Note: This plugin is still under development, and some APIs might not be available yet. FEEDBACK and PULL REQUEST are most welcome!
To use this plugin, add flutter_pushy
as a dependency in your pubspec.yaml file.
dependencies:
flutter_pushy: ^1.0.0
Check out the example
directory for a sample app using Pushy.
Sign up on Pushy website, to access dashboard page and create an app.
To integrate your plugin intot the Android part of your app, follow these steps:
- Using Pushy console create Android app in dashboard.
- (Optional, but recommended) If want to be notified in your app (via onResume) when user clicks on a notification in the system tray, include the following code to your
AndroidManifest.xml
, inside activity tag.
<application>
<activity ...>
...
<intent-filter>
<action android:name="PUSHY_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
To integrate your plugin into the iOS part of your app, follow these steps:
- Using Pushy console create Android app in dashboard.
- Enable push notification capability in Xcode project.
- Setup APNS authentication and export it's authentication key.
From your Dart code, you need to import the plugin and instatiate it:
import 'package:flutter_pushy/flutter_pushy.dart';
final FlutterPushy _pushy = FlutterPushy();
On Android this will bring up write external storage permissions for user to confirm. This is mandatory to prevent multiple token issued for same device for each installation.
_pushy.registerDevice()
.
IOS - This will bring up a permissions dialog for user to confirm on. It's no-op on Android (*if write external storage permission is granted). Pushy will issue a token for each device once device registered, which will be handled in next step.
_pushy.configure(...)
- onMessage triggered when on notification received when app is in foreground. In iOS you must handle in-app notification manually. (ex. use LocalNotification or Dialog widget)
- onResume Triggered on user tap on push notification when app is in background.
- onToken Triggered if device registered successfully to Pushy server.
- onRegisterFail
Triggered if device registration failed, return
500
(network error) or401
(write external storage permissions is denied - Android only).
_pushy.configure(
onMessage: (data) {
print('DATA ON MESSAGE: $data');
if (LocalPlatform().isIOS) {
...
}
...
}, onResume: (data) {
print('DATA ON RESUME: $data');
...
},
onRegisterFail: (err) {
print('failed to register device with code :$err')
...
}
, onToken: (token) {
print('found new Token: $token');
...
});
Refer to Pushy dashboard or startup guide on Android or iOS to send test notification.
Make sure to set Content-Available as true for iOS