Saltar al contenido

notificación de flutter fcm en ejemplo de código de primer plano

Por fin luego de mucho batallar hemos hallado la solución de este atascamiento que ciertos usuarios de este sitio web tienen. Si tienes algo que aportar no dudes en dejar tu información.

Ejemplo 1: las notificaciones locales de flutter no funcionan para el primer plano de ios

import UIKit
import Flutter
import UserNotifications

@UIApplicationMain
@objc classAppDelegate: FlutterAppDelegate, UNUserNotificationCenterDelegate 
  override func application(_application: UIApplication,
    didFinishLaunchingWithOptions launchOptions:[UIApplicationLaunchOptionsKey: Any]?)->Bool
    GeneratedPluginRegistrant.register(with:self)// set the delegate in didFinishLaunchingWithOptions
    UNUserNotificationCenter.current().delegate =selfreturn super.application(application,didFinishLaunchingWithOptions: launchOptions)// This method will be called when app received push notifications in foreground
    func userNotificationCenter(_center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions)->Void)completionHandler([.alert,.badge,.sound])

Ejemplo 2: flutter muestra notificación push en forgrounf

FirebaseMessaging _firebaseMessaging =FirebaseMessaging();
FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =newFlutterLocalNotificationsPlugin();
  @override
  voidinitState()var initializationSettingsAndroid =newAndroidInitializationSettings('@mipmap/ic_launcher');var initializationSettingsIOS =newIOSInitializationSettings();var initializationSettings =newInitializationSettings(
        initializationSettingsAndroid, initializationSettingsIOS);
    flutterLocalNotificationsPlugin.initialize(initializationSettings,onSelectNotification: onSelectNotification);
    _firebaseMessaging.configure(onMessage:(Map<String, dynamic> message) async showNotification(
            message['notification']['title'], message['notification']['body']);print("onMessage: $message");,onLaunch:(Map<String, dynamic> message) async print("onLaunch: $message");
        Navigator.pushNamed(context,'/notify');,onResume:(Map<String, dynamic> message) async print("onResume: $message");,);
Future onSelectNotification(String payload) async showDialog(context: context,builder:(_)returnnewAlertDialog(title:Text("PayLoad"),content:Text("Payload : $payload"),);,);voidshowNotification(String title,String body) async 
    await _demoNotification(title, body);

  Future<void>_demoNotification(String title,String body) async var androidPlatformChannelSpecifics =AndroidNotificationDetails('channel_ID','channel name','channel description',importance: Importance.Max,playSound:true,sound:'sound',showProgress:true,priority: Priority.High,ticker:'test ticker');var iOSChannelSpecifics =IOSNotificationDetails();var platformChannelSpecifics =NotificationDetails(
        androidPlatformChannelSpecifics, iOSChannelSpecifics);
    await flutterLocalNotificationsPlugin
        .show(0, title, body, platformChannelSpecifics,payload:'test');

Puntuaciones y comentarios

Si eres capaz, puedes dejar un tutorial acerca de qué te ha gustado de este tutorial.

¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *