- Бэкэнд отправляет уведомление в ios с использованием пакета node-apn (непосредственно с использованием apn)
- Ток APN извлекается с помощью Firebase.
A.используется FCM для отправки уведомлений для Android и apn для iOS. Android работает нормально во всех случаях.
Б. использовал node-apn. Для apn ios alert push: я не могу извлечь полезную нагрузку. (При нажатии на уведомление я хочу открыть определенный экран в зависимости от полезной нагрузки.)
Код для отправки уведомления:
Код узла сервера:
Код: Выделить всё
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())
Код: Выделить всё
{
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'
}
Как я могу извлечь параметры?
ниже приведен мой AppDelegates.swift в проекте flutter:
Код: Выделить всё
@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("")
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... ation-in-f