搜索插件、代码仓与 APP 分类

插件详情v0.0.4

plain_notification_token

通过平台方式获取推送通知令牌(iOS 使用 APNs,Android 使用 Firebase Cloud Messaging)

AndroidiOS
近 30 天下载
70
喜欢数
41
Pub 分数
130

安装插件

flutter pub add plain_notification_token

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个轻量级的 Flutter 包,使用平台特定的方法获取推送通知令牌:iOS 使用 APNs,Android 使用 Firebase Cloud Messaging。它抽象了底层实现,使开发者能够轻松获取设备令牌以发送通知。该包设计简洁可靠,确保跨平台的一致性令牌访问,无需复杂的设置。它可无缝集成到需要推送通知功能的应用中。

适合场景

  • 获取推送通知的设备令牌
  • 与 Firebase 云消息传递集成
  • 在 iOS 上设置 APNs 令牌
  • 启用跨平台通知支持
  • 简化消息应用中的令牌获取

主要特点

  • 平台特定的令牌检索
  • 最小化样板
  • 支持 Android 和 iOS
  • 与 FCM 和 APNs 的轻松集成
  • 轻量且无依赖

适合对象

  • 需要推送通知的应用
  • 使用 FCM 或 APNs 的开发人员
  • 优先考虑简单性的项目
  • 跨平台移动应用
  • 管理设备令牌的后端服务

使用建议

  • 需要正确设置 FCM 或 APNs
  • 不自动处理令牌刷新
  • 没有内置的网络问题错误处理
  • 仅限令牌检索
  • 依赖外部服务进行实际消息传递

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

plain_notification_token

Get your push notification token via platform way (APNs for iOS / Firebase Clound Messaging for Android)

Getting Started

Android Integration

To integrate your plugin into the Android part of your app, setup Firebase:

  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. Modify the android/build.gradle file and the android/app/build.gradle file to add the Google services plugin as described by the Firebase assistant.

(Please see this tutorial if you want.)

iOS Integration

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

  1. Generate the certificates from Apple developer center for receiving push notifications. (Please see this article if you want the tutorial.)
  2. Enable Push Notification in Capabilities tab in Xcode opening your ios/Runner.xcworkspace.

Enabling Push Notification switch

Dart/Flutter Integration

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

import 'package:plain_notification_token/plain_notification_token.dart';

final plainNotificationToken = PlainNotificationToken();

To get token, call getToken():

// (iOS Only) Need requesting permission of Push Notification.
if (Platform.isIOS) {
  plainNotificationToken.requestPermission();
  
  // If you want to wait until Permission dialog close,
  // you need wait changing setting registered. 
  await plainNotificationToken.onIosSettingsRegistered.first;
}

final String token = await plainNotificationToken.getToken();

... and use token on your server!!

Token is Base64 stringified APNs token (in iOS) / Firebase Cloud Messaging (FCM) string token (in Android).

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目