Code Monkey home page Code Monkey logo

azure-notificationhubs-flutter's Introduction

This plugin is not maintained anymore. I am not answering any more questions. I will gladly point to your fork if you are going to continue to work on this.

Regards,

@19hours

Microsoft Azure Notification Hubs wrapper for Flutter

Pub Version

This is a work in progress. View todos in our issues page for more information. Please submit PR!

Microsoft Azure Notification Hubs provide a multiplatform, scaled-out push infrastructure that enables you to send mobile push notifications from any backend (in the cloud or on-premises) to any mobile platform. To learn more, visit the Developer Center.

Getting Started

If you are new to Notification Hubs, you can get started by following the tutorials to push notifications to your apps.

Configuration

Android Integration

To integrate your plugin into the Android part of your app, follow these steps:

  1. Using the Firebase Console add an Android app to your project: Follow the assistant, download the generated google-services.json file and place it inside android/app.

  2. Add your notification hub name and connection string to android/app/src/main/AndroidManifest.xml.

<meta-data 
    android:name="NotificationHubName"
    android:value="" />
<meta-data 
    android:name="NotificationHubConnectionString"
    android:value="Endpoint=..." />
  1. Add permissions to android/app/src/main/AndroidManifest.xml.
  <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.GET_ACCOUNTS"/>
  <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

iOS Integration

To integrate your plugin into the iOS part of your app, follow these steps:

  1. Generate the certificates required by Apple for receiving push notifications following this guide in the Azure docs.

  2. Register your app for push notifications with Apple following this guide in the Azure docs.

  3. In Xcode, select Runner in the Project Navigator. In the Capabilities Tab turn on Push Notifications and Background Modes, and enable Background fetch and Remote notifications under Background Modes.

  4. Add your notification hub name and connection string to Info.plist.

NotificationHubName
NotificationHubConnectionString

Dart/Flutter Integration

From your Dart code, you need to import the plugin and instantiate it:

import 'package:azure_notificationhubs_flutter/azure_notificationhubs_flutter.dart';

final AzureNotificationhubsFlutter _anh = AzureNotificationhubsFlutter();

Requesting permissions on iOS is managed by the plugin and the request will bring up a permissions dialog for the user to confirm on iOS on app launch.

Afterwards, you can listen to the notifications and write your own logic to handle extra data payloads.

  _anh.configure(
    onLaunch: (Map<String, dynamic> notification) async {
      print('onLaunch: $notification');
    },
    onResume: (Map<String, dynamic> notification) async {
      print('onResume: $notification');
    },
    onMessage: (Map<String, dynamic> notification) async {
      print('onMessage: $notification');
    },
    onToken: (String token) async {
      print('onToken: $token');
    },
  );

Payloads

iOS and Android have different payloads. The entire payload will be sent to dart onResume, onLaunch, onMessage depending on the situation.

iOS Payload

{
    aps: {
      alert: {
        title: "Hello world",
        body: "by chu"
      },
      badge: 1
    },
    <!-- extra data payload -->
    ...
  }

Android Payload

Send the title as an empty string if it is not required.

{
  "data": {
    "title": "Hello world",
    "body": "to you",
    <!-- extra data payload -->
    ...
  }
}

Subscribing to tags

Every device is automatically subscribed to device:deviceID. For Android, deviceId is a SHA1 hash of FirebaseCloudMessaging token because it exceeds the length limits of a tag.

Manual subscribing to tags is not supported as it is not my priority right now. Feel free to create a PR.

Why am I receiving silent notifications on android?

It's a feature, not a bug. In android, sometimes the user does not receive any heads up notifications and the notifications appear silently in the notification drawer. This is because heads up notifications have a built in rate limiting - if the user swipes your heads up notification up (putting it back into the notification tray) or to the side (dismissing it), then the system prevents further heads up notifications for some period of time.

Download Source Code

To get the source code of our wrapper via git just type:

git clone https://github.com/rswiftoffice/azure-notificationhubs-flutter.git

Contributing

If you're unsure about anything, just ask -- or submit the issue or pull request anyway. The worst that can happen is you'll be politely asked to change something. We love all friendly contributions.

azure-notificationhubs-flutter's People

Watchers

 avatar

Forkers

dimakutko

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.