一个用于处理 VoIP 推送通知的 Flutter 插件,目前支持 iOS 8.0 及以上版本。它使实时通信应用即使在应用被终止的情况下也能接收推送通知,确保可靠的通话连接。该包与 Apple 的推送通知服务(APNs)集成,以传递静音 VoIP 通知,从而在后台激活应用以接收来电。专为语音-over-IP 应用设计,如 VoIP 通话或需要即时通知传递的消息平台。可在 Flutter 生态系统中无缝运行,设置简单。目前不支持 Android。
适合场景
实时VoIP通话应用
后台呼叫通知
静默推送通知处理
来电时唤醒应用
语音通信平台
主要特点
仅限 iOS 的 VoIP 推送支持
静默通知传递
后台应用激活
Apple APNs 集成
所需最小配置
适合对象
VoIP 应用开发者
实时通信应用
专注于 iOS 的 Flutter 项目
呼叫路由系统
需要可靠后台通知的应用
使用建议
无 Android 支持
需要 iOS 8.0 或更高版本
需要设置 APNs 证书
仅限VoIP使用场景
依赖于苹果的推送基础设施
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
Flutter VoIP Push Notification
Flutter VoIP Push Notification - Currently iOS >= 8.0 only
Motivation
Since iOS 8.0 there is an execellent feature called VoIP Push Notification (PushKit), while firebase_messaging does not support voip push notification which is only available on iOS >= 8.0 which is the reason for this plugin.
To understand the benefits of Voip Push Notification, please see VoIP Best Practices.
import'package:flutter/material.dart';
import'package:flutter/material.dart';
import'dart:async';
import'package:flutter_voip_push_notification/flutter_voip_push_notification.dart';
voidmain() => runApp(MyApp());
classMyAppextendsStatefulWidget{
@override_MyAppStatecreateState() => _MyAppState();
}
class_MyAppStateextendsState<MyApp> {
String _pushToken = '';
FlutterVoipPushNotification _voipPush = FlutterVoipPushNotification();
@overridevoidinitState() {
super.initState();
configure();
}
// Configures a voip push notificationFuture<void> configure() async {
// request permission (required)await _voipPush.requestNotificationPermissions();
// listen to voip device token changes
_voipPush.onTokenRefresh.listen(onToken);
// do configure voip push
_voipPush.configure(onMessage: onMessage, onResume: onResume);
}
/// Called when the device token changesvoidonToken(String token) {
// send token to your apn provider serversetState(() {
_pushToken = token;
});
}
/// Called to receive notification when app is in foreground////// [isLocal] is true if its a local notification or false otherwise (remote notification)/// [payload] the notification payload to be processed. use this to present a local notificationFuture<dynamic> onMessage(bool isLocal, Map<String, dynamic> payload) {
// handle foreground notificationprint("received on foreground payload: $payload, isLocal=$isLocal");
returnnull;
}
/// Called to receive notification when app is resuming from background////// [isLocal] is true if its a local notification or false otherwise (remote notification)/// [payload] the notification payload to be processed. use this to present a local notificationFuture<dynamic> onResume(bool isLocal, Map<String, dynamic> payload) {
// handle background notificationprint("received on background payload: $payload, isLocal=$isLocal");
showLocalNotification(payload);
returnnull;
}
showLocalNotification(Map<String, dynamic> notification) {
String alert = notification["aps"]["alert"];
_voipPush.presentLocalNotification(LocalNotification(
alertBody: "Hello $alert",
));
}
@overrideWidgetbuild(BuildContext context) {
returnMaterialApp(
home: Scaffold(
appBar: AppBar(
title: constText('Plugin example app'),
),
body: Center(
child: Text('Received Voip Push token: $_pushToken\n'),
),
),
);
}
}