ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • flutter_local_notifications 설정
    firebase 2023. 2. 23. 11:15
    반응형

    flutter_local_notifications: ^13.0.0


    Android

    main/AndroidManifest.xml

     <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
     <uses-permission android:name="android.permission.VIBRATE" />
     <uses-permission android:name="android.permission.WAKE_LOCK" />
     <uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
    

    부팅 시 서비스 실행, 진동, 알림 오면 화면 열리기, full screen 인텐트 사용 허용


    // Android
    const AndroidInitializationSettings initAndroid =
        AndroidInitializationSettings('@drawable/ic_stat_notification');
    // iOS
    late DarwinInitializationSettings initDarwin;
    
    // notification init
    static Future<void> init() async {
        initDarwin = const DarwinInitializationSettings(
          onDidReceiveLocalNotification: onDidReceiveLocalNotification,
        );
    
        initializationSettings = InitializationSettings(
          android: initAndroid,
          iOS: initDarwin,
        );
    
        await localNotification.initialize(
          initializationSettings,
          onDidReceiveNotificationResponse: selectNotification,
          onDidReceiveBackgroundNotificationResponse: selectNotification,
        );
      }
    

    포어그라운드 알림 생성

    AndroidNotificationDetails androidDetail = const AndroidNotificationDetails(
        'team_chat_id',
        'team_chat_name',
        channelDescription: '',
        importance: Importance.max,
        priority: Priority.high,
        playSound: true,
        icon: '@drawable/ic_stat_notification',
      );
    

    ※ 백그라운드 아이콘은 AndroidManifest.xml 에서

    여기서 관리함


    Ios

    ios 는 특성상 foreground에서는 알림이 작동되지 않게 설정되어있다.

    해당 코드를 입력시 foreground에서도 작동이 되도록 설정한다.

    if #available(iOS 10.0, *) {
       UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
    }
    

    알림 생성

    DarwinNotificationDetails iosDetail = const DarwinNotificationDetails(
        presentAlert: true,
        presentBadge: true,
        presentSound: true,
      );
    

     

    반응형

    댓글

Designed by Tistory.