• Stars
    star
    144
  • Rank 247,608 (Top 6 %)
  • Language
    Dart
  • License
    MIT License
  • Created about 5 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Flutter Plugin for Push notification servers

apns

⛔️ DEPRECATED ⛔️

This package is not longer maintained. Please write message or GitHub issue if you want to take it over and end deprecated state.

Plugin to implement APNS push notifications on iOS and Firebase on Android.

Why this plugin was made?

Currently, the only available push notification plugin is firebase_messaging. This means that, even on iOS, you will need to setup firebase and communicate with Google to send push notification. This plugin solves the problem by providing native APNS implementation while leaving configured Firebase for Android.

Usage

  1. Configure firebase on Android according to instructions: https://pub.dartlang.org/packages/firebase_messaging.

  2. On iOS, make sure you have correctly configured your app to support push notifications, and that you have generated certificate/token for sending pushes. For more infos see section How to run example app on iOS

  3. Add the following lines to the didFinishLaunchingWithOptions method in the AppDelegate.m/AppDelegate.swift file of your iOS project

Objective-C:

if (@available(iOS 10.0, *)) {
  [UNUserNotificationCenter currentNotificationCenter].delegate = (id<UNUserNotificationCenterDelegate>) self;
}

Swift:

if #available(iOS 10.0, *) {
  UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
}
  1. Add flutter_apns as a dependency in your pubspec.yaml file.
  2. Using createPushConnector() method, configure push service according to your needs. PushConnector closely resembles FirebaseMessaging, so Firebase samples may be useful during implementation. You should create the connector as soon as possible to get the onLaunch callback working on closed app launch.
import 'package:flutter_apns/apns.dart';

final connector = createPushConnector();
connector.configure(
    onLaunch: _onLaunch,
    onResume: _onResume,
    onMessage: _onMessage,
);
connector.requestNotificationPermissions()
  1. Build on device and test your solution using Firebase Console (Android) and CURL (iOS, see How to run example app on iOS).

Additional APNS features:

Displaying notification while in foreground

final connector = createPushConnector();
if (connector is ApnsPushConnector) {
  connector.shouldPresent = (x) => Future.value(true);
}

Handling predefined actions

Firstly, configure supported actions:

final connector = createPushConnector();
if (connector is ApnsPushConnector) {
  connector.setNotificationCategories([
    UNNotificationCategory(
      identifier: 'MEETING_INVITATION',
      actions: [
        UNNotificationAction(
          identifier: 'ACCEPT_ACTION',
          title: 'Accept',
          options: [],
        ),
        UNNotificationAction(
          identifier: 'DECLINE_ACTION',
          title: 'Decline',
          options: [],
        ),
      ],
      intentIdentifiers: [],
      options: [],
    ),
  ]);
}

Then, handle possible actions in your push handler:

Future<dynamic> onPush(String name, RemoteMessage payload) {
  final action = UNNotificationAction.getIdentifier(payload.data);

  if (action == 'MEETING_INVITATION') {
    // do something
  }

  return Future.value(true);
}

Note: if user clickes your notification while app is in the background, push will be delivered through onResume without actually waking up the app. Make sure your handling of given action is quick and error free, as execution time in for apps running in the background is very limited.

Check the example project for fully working code.

Enabling FirebaseCore

If you want to use firebase, but not firebase messaging, add this configuration entry in your Info.plist (to avoid MissingPluginException):

<key>flutter_apns.disable_firebase_core</key>
<false/>

flutter_apns_only - APNS without firebase

If only care about apns - use flutter_apns_only plugin. It does not depend on firebase. To ensure no swizzling (which is needed by original plugin to disable firebase) takes place, add this configuration entry in your Info.plist:

<key>flutter_apns.disable_swizzling</key>
<true/>

Troubleshooting

  1. Ensure that you are testing on actual device. NOTE: this may not be needed from 11.4: https://ohmyswift.com/blog/2020/02/13/simulating-remote-push-notifications-in-a-simulator/
  2. If onToken method is not being called, add error logging to your AppDelegate, see code below.
  3. Open Console app for macOS, connect your device, and run your app. Search for "PUSH registration failed" string in logs. The error message will tell you what was wrong.

swift

import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }

  func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
     NSLog("PUSH registration failed: \(error)")
  }
}

objc

#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [GeneratedPluginRegistrant registerWithRegistry:self];
  // Override point for customization after application launch.
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    NSLog(@"%@", error);
}

@end

How to run example app on iOS

Setting up push notifications on iOS can be tricky since there is no way to permit Apple Push Notification Service (APNS) which requires a complicated certificate setup. The following guide describes a step by step approach to send push notifications from your Mac to an iPhone utilizing the example app of this package. This guide only describes debug environment setup.

  1. Open example ios folder with Xcode
  2. Select Runner -> Signing & Capabilities
  3. Select your development team and add a globally unique bundle identifier. The one on the picture is already occupied:
  4. Go to https://developer.apple.com/account/resources/identifiers/list/bundleId and press on the plus button
  5. Select "App IDs" and press continue
  6. Select type "App"
  7. Select "App ID Prefix" which should be same as "Team ID"
  8. Enter description and bundle ID. The latter one needs to be the same as the bundle ID specified in 3.
  9. Select push notification capability
  10. Press on "Continue" and then on "Register"
  11. Go to https://developer.apple.com/account/resources/certificates and add a new certificate by pressing on the plus-button.
  12. Select 'Apple Push Notification service SSL (Sandbox & Production)'
  13. Select the app ID that you hav defined in point 4.-10.
  14. Select a Certificate Signing Request (CSR) file. See https://help.apple.com/developer-account/#/devbfa00fef7 on how to create this certificate
  15. When having finished, download the newly created Apple Push Services certificate
  16. Add certificate to your local keychain by opening the newly downloaded file
  17. Press on "login" on the upper left corner of your keychain window and select the tab "My Certificates"
  18. Right click on the Apple-Push-Services-certificate and export it as .p12-file
  19. Convert p12-file to pem-file by following command. Please consider that "flutterApns" needs to be replaced by your respective certificate name.
    More info
    openssl pkcs12 -in flutterApns.p12 -out flutterApns.pem -nodes -clcerts
    
  20. Start example app on physical iPhone device from Xcode or your favorite IDE.
  21. Device token gets automatically printed when application was able to retrieve push token from APNS. This happens after accepting notification permission prompt.
  22. Send the following CURL from you development Mac. You can execute CURLs by copy-pasting them into Terminal and hit enter.
    More info
    curl -v \
    -d '{"aps":{"alert":"<your_message>","badge":2}}' \
    -H "apns-topic: <bundle_identifier_of_registered_app>" \
    -H "apns-priority: 10" \
    --http2 \
    --cert <file_path_to_downloaded_signed_and_converted_certificate>.pem \
    https://api.development.push.apple.com/3/device/<device_token>
    
  23. A push notification does appear if the example app is in background.

When not utilizing the example app, you need to additionally setup push notification capability inside Xcode and add the code mentioned in usage.

More Repositories

1

The-M-Project

'The-M-Project' is a Mobile HTML5 Application Framework.
CSS
748
star
2

generator-m-ionic

Advanced workflows and setup for building rock-solid Ionic apps
JavaScript
671
star
3

fruitymesh

FruityMesh - The first completely connection-based open source mesh on top of Bluetooth Low Energy (4.1/5.0 or higher)
C
283
star
4

titanium-barcode

barcode scanner module for appcelerator titanium
Java
120
star
5

Espresso

The-M-Projects build tools using node.js.
JavaScript
84
star
6

The-M-Project-Sample-Apps

The-M-Project Sample Apps
JavaScript
67
star
7

generator-m-ionic-demo

A demo project generated with generator-m-ionic
JavaScript
27
star
8

titanium-barcode-example

A sample application using the titanium-barcode module
JavaScript
24
star
9

cordova-plugin-client-certificate

Client certificate authentication plugin for Cordova
Objective-C
16
star
10

bikini

Offline Synchronisation for Backbone (deprecated)
JavaScript
14
star
11

brackets-quick-require

JavaScript
11
star
12

cordova-plugin-inappbrowser

Java
9
star
13

fruitymesh-devenv

Development Environment for FruityMesh - saves you some trouble
HTML
8
star
14

bigbench.js

BigBench.js
JavaScript
7
star
15

relution-jenkins-plugin

A Jenkins plugin for the Relution Enterprise Appstore by M-Way Solutions GmbH
Java
7
star
16

mcap-cli

JavaScript
6
star
17

Sketch_Sir_Explain-A-Lot

A Sketch Plugin for explaining your awesome Designs (Alpha)
JavaScript
5
star
18

tslint-config-mway

A TSLint config for M-Way Typescript Style Guide
JavaScript
5
star
19

generator-themproject

Generator for The-M-Project 2.0
JavaScript
4
star
20

uikit

Ui toolbox to build single page web applications with Angular 1.x
JavaScript
4
star
21

update-manager

JavaScript
3
star
22

BlueRange-SDK-Android

Android SDK for interaction with Relution SmartBeacons
Java
3
star
23

flutter-zebra-datawedge

Java
2
star
24

mcapjs-client

JavaScript
2
star
25

cloud9mobile

Don't use this branch - there is nothing to see
JavaScript
2
star
26

relution-client-security

A Login/Logout Module for Relution LiveData. Works well with generator-m
JavaScript
2
star
27

android-maven-string-replacement

A showcase about howto replace a string inside /res/values/strings.xml via maven. A Use-case is handling the Google Maps API keys
Java
2
star
28

generator-m-server

JavaScript
1
star
29

angularjs-mcap-session

AngularJS module for session management with mCAP backends.
JavaScript
1
star
30

generator-appmobi

DEPRECATED! generator for appmobi integration into generator-m-ionic
JavaScript
1
star
31

JmDNS

fork of http://jmdns.sourceforge.net/
Java
1
star
32

Reboard-Proxy

Our reverse HTTP proxy for Reboard
JavaScript
1
star
33

flutter-managed-configuration

Java
1
star
34

ionic2-playground

some examples for ionic2
JavaScript
1
star
35

relution-livedata-sample-chat

JavaScript
1
star
36

tmpl

A more specific template engine using stickit and backbone
JavaScript
1
star
37

BlueRange-SDK-iOS

iOS SDK for interaction with Relution SmartBeacons
Objective-C
1
star
38

uikit-sample-portal

Sample portal using the mw-uikit
JavaScript
1
star
39

Catoo

Catoo is a powerful and easy to use catalog framework. Present your products in your branded catalog app on the iPad. Download Catoo, integrate your catalog and publish your app! Premium catalogs, brochures, training materials and manuals can be developed in just a few steps. Optionally thrilling multimedia and shopping features can be added. Developers benefit from a superfast rendering and a compelling usability.
Objective-C
1
star