Огненная база Swizzling уже отключена < /li>
apns token. Messaging.messaging (). AppdidReceiveMessage (userInfo) < /li>
Самоуверенные (ios, Firebase, Clevertap) < /li>
< /ol>
Проблема: реализация Clevertap в местных ios, в Appdelegate, чтобы быть конкретным; вызывает проблемы с нашей реализацией Firebase по обработке получения сообщений. Каждый раз, когда я использую iOS, функция Clevertap по -прежнему работает, но FireBaseMessaging.onmessage.listen нет более длинные работы
Вот Appdelegate.swift
Код: Выделить всё
import UIKit
import Flutter
import Firebase
import CleverTapSDK
import clevertap_plugin
import AppTrackingTransparency
// This is required for calling FlutterLocalNotificationsPlugin.setPluginRegistrantCallback method.
import flutter_local_notifications
@main
@objc class AppDelegate: FlutterAppDelegate, MessagingDelegate, CleverTapPushNotificationDelegate {
private var flutterViewController: FlutterViewController!
private var securityChannel: FlutterMethodChannel!
private var blurEffectView: UIVisualEffectView?
private var isInBackground: Bool = false // Track whether app is in background
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
CleverTap.autoIntegrate()
CleverTapPlugin.sharedInstance()?.applicationDidLaunch(options: launchOptions)
CleverTap.setDebugLevel(CleverTapLogLevel.debug.rawValue)
FirebaseApp.configure()
Messaging.messaging().delegate = self
var flutter_native_splash = 1
UIApplication.shared.isStatusBarHidden = false
// This is required to make any communication available in the action isolate.
FlutterLocalNotificationsPlugin.setPluginRegistrantCallback { (registry) in
GeneratedPluginRegistrant.register(with: registry)
}
registerForPush()
GeneratedPluginRegistrant.register(with: self)
setupFlutterCommunication()
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
}
private func setupFlutterCommunication() {
flutterViewController = window?.rootViewController as? FlutterViewController
securityChannel = FlutterMethodChannel(
name: "security",
binaryMessenger: flutterViewController.binaryMessenger
)
securityChannel.setMethodCallHandler(handle)
}
override func applicationDidEnterBackground(_ application: UIApplication) {
isInBackground = true // App entered background
enableAppSecurity()
}
override func applicationDidBecomeActive(_ application: UIApplication) {
if #available(iOS 15.0, *) {
ATTrackingManager.requestTrackingAuthorization(completionHandler: {
status in
})
}
// Check if the app was in background before becoming active
if isInBackground {
disableAppSecurity()
isInBackground = false
}
}
private func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
switch call.method {
case "enableAppSecurity":
result(nil)
case "disableAppSecurity":
result(nil)
default:
result(FlutterMethodNotImplemented)
}
}
private func enableAppSecurity() {
let blurEffect = UIBlurEffect(style: .light)
blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView?.frame = window!.frame
window?.addSubview(blurEffectView!)
}
private func disableAppSecurity() {
blurEffectView?.removeFromSuperview()
}
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
let dataDict: [String: String] = ["token": fcmToken ?? ""]
NotificationCenter.default.post(
name: Notification.Name("FCMToken"),
object: nil,
userInfo: dataDict
)
// TODO: If necessary send token to application server.
// Note: This callback is fired at each app startup and whenever a new token is generated.
}
func registerForPush() {
// register category with actions
let action1 = UNNotificationAction(identifier: "action_1", title: "Back", options: [])
let action2 = UNNotificationAction(identifier: "action_2", title: "Next", options: [])
let action3 = UNNotificationAction(identifier: "action_3", title: "View In App", options: [])
let category = UNNotificationCategory(identifier: "CTNotification", actions: [action1, action2, action3], intentIdentifiers: [], options: [])
UNUserNotificationCenter.current().setNotificationCategories([category])
UNUserNotificationCenter.current().delegate = self
// request Permissions
UNUserNotificationCenter.current().requestAuthorization(options: [.sound, .badge, .alert], completionHandler: {granted, error in
if granted {
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
})
}
//Background/Terminated state Clevertap notification receiver
override func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo // payload
let application = UIApplication.shared // Get the shared application instance
NSLog("AppDelegate: didReceiveResponse: Notification Tapped. UserInfo: %@", userInfo)
// --- Process with CleverTap SDK (ONLY if it's a CleverTap Notification) ---
// This is the CRITICAL call for all CleverTap notification clicks.
// CleverTap's SDK will:
// 1. Record a "Notification Clicked" event in analytics.
// 2. Bridge the payload to Dart's clevertap_plugin (triggering your setCleverTapPushClickedPayloadReceivedHandler
// or making it available for getAppLaunchNotification).
if CleverTap.sharedInstance()!.isCleverTapNotification(userInfo) {
NSLog("AppDelegate: CleverTap notification detected. Handling with CleverTap SDK.")
CleverTap.sharedInstance()!.handleNotification(withData: userInfo)
let channel = FlutterMethodChannel(name: "notificationTapChannel", binaryMessenger:flutterViewController.binaryMessenger)
channel.invokeMethod("iosPushNotificationClicked", arguments: userInfo)
} else {
NSLog("AppDelegate: Non-CleverTap notification tap received. UserInfo: %@", userInfo)
// For non-CleverTap notification taps, FirebaseMessaging.onMessageOpenedApp.listen
// in Dart will automatically handle this. No specific native code needed here to send to Flutter.
// If you had other specific non-CleverTap tap handling, it would go here.
}
completionHandler() // Always call to tell OS processing is complete
}
// Foreground
override func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
if CleverTap.sharedInstance()!.isCleverTapNotification(userInfo) {
NSLog("AppDelegate: CleverTap notification detected. Received with CleverTap SDK.")
completionHandler([.badge, .sound, .alert])
} else {
NSLog("AppDelegate: Non-CleverTap notification tap received. UserInfo: %@", userInfo)
Messaging.messaging().appDidReceiveMessage(userInfo)
completionHandler([])
}
}
//Push Notification Callback Background/Foreground/Terminated
func pushNotificationTapped(withCustomExtras customExtras: [AnyHashable : Any]!) {
print("Push Notification Tapped with Custom Extras: \(customExtras)");
}
}
< /code>
Вот main.dart с Firebasemessaging.onmessage < /p>
// fire the local push notification on foreground
FirebaseMessaging.onMessage.listen(
(RemoteMessage message) {
if (message.notification != null) {
Logger.log('Firebase messaging 1: receive notification', 'receive notification: ${message.notification}');
// ~/ is truncating division, it means that the result will be automatically converted to int
// you need to use dynamic ID in order to receive multiple notification in the system tray
int notificationId = DateTime.now().millisecondsSinceEpoch ~/ 1000;
Logger.log('Firebase messaging 2: show notif', 'notification: ${message.notification?.toMap().toString() ?? ''}');
// here more function or code handling for every receive of push notification we call add a bloc event.
}
);
Каждый раз, когда я удаляю реализацию Clevertap в приложении, в частности, части didReceive и Will Present formine Functions заставляет флаттер inmessage.listen работает. Совместимо путем вручную реализовывать оба и иметь условные функции, чтобы знать, какая и какая функция вызывает; < /li>
< /ol>
Messaging.messaging().appDidReceiveMessage(userInfo)
< /code>
или < /p>
CleverTap.sharedInstance()!.handleNotification(withData: userInfo)
< /code>
Есть ли возможность сделать эти два совместимых? Или мне не хватает какой -либо реализации?>
Подробнее здесь: https://stackoverflow.com/questions/796 ... fication-h
Мобильная версия