一個用於處理 VoIP 推送通知的 Flutter 插件,目前支援 iOS 8.0 及以上版本。它讓即時通訊應用即使在應用程式終止的情況下也能接收推播通知,確保可靠的通話連接。此套件與 Apple 的推播通知服務(APNs)整合,以傳遞靜音 VoIP 通知,進而於背景啟動應用程式以接收來電。專為語音過 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'),
),
),
);
}
}