skip to Main Content

I am trying to send push notifications to my flutter app.

I tested android and it worked perfectly. However, ios did not work out.
Is there any progress work that I should do for the ios setting?
I did not register for the apple developer program yet.

Please help out. Somebody help me….

I will leave the code below

import 'package:get/get.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:firebase_in_app_messaging/firebase_in_app_messaging.dart';

class NotificationPresenter extends GetxController {
FirebaseMessaging messaging = FirebaseMessaging.instance;

@override
void onInit() async{
NotificationSettings settings = await messaging.requestPermission(
  alert: true,
  announcement: true,
  badge: true,
  carPlay: true,
  criticalAlert: true,
  provisional: true,
  sound: true,
);
print(settings.authorizationStatus);
_getToken();
_onMessage();
super.onInit();
}
void _getToken() async{
String? token= await messaging.getToken();
try{
  print(token);
} catch(e) {}
}
final AndroidNotificationChannel channel = const AndroidNotificationChannel(
'high_importance_channel', // id
'High Importance Notifications', // title
description: 'This channel is used for important notifications.', // description
importance: Importance.max,
);
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
void _onMessage() async{
await flutterLocalNotificationsPlugin
    .resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>()
    ?.createNotificationChannel(channel);
await flutterLocalNotificationsPlugin.initialize(
    const InitializationSettings(
        android: AndroidInitializationSettings('@mipmap/ic_launcher'), iOS: IOSInitializationSettings()),
    onSelectNotification: (String? payload) async {});

FirebaseMessaging.onMessage.listen((RemoteMessage message) {
  RemoteNotification? notification = message.notification;
  AndroidNotification? android = message.notification?.android;

  if (notification != null && android != null) {
    flutterLocalNotificationsPlugin.show(
      notification.hashCode,
      notification.title,
      notification.body,
      NotificationDetails(
        android: AndroidNotificationDetails(
            channel.id,
            channel.name,
            channelDescription: channel.description
        ),
      ),
      // payload: message.data['argument']
    );
  }
  print('foreground 상황에서 메시지를 받았다.');
  print('Message data: ${message.data}');
  if (message.notification != null) {
    print('Message also contained a notification: ${message.notification!.body}');
  }
});
}
}

2

Answers


  1. There are quite a few steps in case of ios

    1. Registering a bundle id

    2. Registering a provision profile

    3. Enabling push notification service for that profile

    4. Generating an apns (Apple push notification service) key

    5. Adding this apns to firebase

    6. Creating an ios id in firebase

    7. Downloading the Google service info plist and adding it to the project

    These steps are all required to recieve push notification in ios

    Login or Signup to reply.
  2. Follow this step for flutter integration for setting up the APN certificate with cloud messaging

    Set up for certificate and APNs

    After completing certification step download the GoogleService-Info.plist and add it using Xcode.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search