- Backend sendet Benachrichtigungen an iOS mithilfe des Node-APN-Pakets (direkt mithilfe von APN)
- APN-Toke wird mit Firebase abgerufen.
A. hat FCM verwendet, um Benachrichtigungen für Android und APN zu senden IOS. Android funktioniert in allen Fällen einwandfrei.
B. Verwendeter Knoten-APN Für APN iOS Alert Push: Ich kann die Nutzlast nicht extrahieren. (Beim Tippen auf die Benachrichtigung möchte ich je nach Nutzlast einen bestimmten Bildschirm öffnen.)
Code zum Senden der Benachrichtigung:
Knotenservercode:
Code: Select all
var apnProvider = new apn.Provider(apnOptions);
var note = new apn.Notification();
//Set contents for note here
…
apnProvider
.send(note, token obtained from FirebaseMessaging.instance.getAPNSToken())
Code: Select all
{
encoding: 'utf8',
payload: {
messageFrom: 'Health',
params: {
title: 'Health',
body: 'Hello, You have a request. Kindly check.',
notification_type: 18,
appointment_id: "610cc37686000662ad14c",
send_time_in_ms: 1736510662242
}
},
compiled: false,
expiry: 1736514262,
priority: 10,
topic: ‘mytopic,
pushType: 'alert'
}
Wie kann ich Parameter extrahieren?
unten ist mein AppDelegates.swift im Flutter-Projekt:
Code: Select all
@main
@objc class AppDelegate: FlutterAppDelegate, PKPushRegistryDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// This is required to make any communication available in the action isolate.
FlutterLocalNotificationsPlugin.setPluginRegistrantCallback { (registry) in
GeneratedPluginRegistrant.register(with: registry)
}
// Added as per documentation of flutter local notification package
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
}
GeneratedPluginRegistrant.register(with: self)
//Setup VOIP (flutter_callkit_incomming)
let mainQueue = DispatchQueue.main
let voipRegistry: PKPushRegistry = PKPushRegistry(queue: mainQueue)
voipRegistry.delegate = self
voipRegistry.desiredPushTypes = [PKPushType.voIP]
print("didFinishLaunchingWithOptions")
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
// As per flutter_callkit_incomming Start ///////////////////
// Handle updated push credentials
func pushRegistry(_ registry: PKPushRegistry, didUpdate credentials: PKPushCredentials, for type: PKPushType) {
print(credentials.token)
let deviceToken = credentials.token.map { String(format: "%02x", $0) }.joined()
print(deviceToken)
//Save deviceToken to your server
SwiftFlutterCallkitIncomingPlugin.sharedInstance?.setDevicePushTokenVoIP(deviceToken)
}
func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenFor type: PKPushType) {
print("didInvalidatePushTokenFor")
SwiftFlutterCallkitIncomingPlugin.sharedInstance?.setDevicePushTokenVoIP("")
}