Berke Ay
Berke Ay

Reputation: 93

Flutter local notification is not working as expected on IOS

My codes are below. It is working very well on Android devices but when I click the notification, it doesn't open specific screen on IOS. It just opens the app. I want it open the spesific screen.

    Future<void>  initSettings() async {
    
    
    var initAndorid = AndroidInitializationSettings('my_logo');
    var initIOS = IOSInitializationSettings(
      requestSoundPermission: false,
      requestBadgePermission: false,
      requestAlertPermission: false,
    );
    var initSetting =InitializationSettings(android: initAndorid, iOS: initIOS);
     notificationsPlugin = new FlutterLocalNotificationsPlugin();
    await notificationsPlugin.initialize(initSetting,
        onSelectNotification: notificationSelected);
  }

  Future notificationSelected(String? payload) async {
     
     await Navigator.push(
        context,
        MaterialPageRoute(builder: (context) => SpesificScreen())
    ); 
  }

It's working on Android devices. What should I do? Thanks in advance...

Upvotes: 2

Views: 1243

Answers (1)

Mojtaba Ghiasi
Mojtaba Ghiasi

Reputation: 983

You can use this code on your app startup to give notification's payload or details that cause to open app and do navigate or every other work we want to do :

var details = await FlutterLocalNotificationsPlugin().getNotificationAppLaunchDetails();
if (details.didNotificationLaunchApp) {
 await Navigator.push(
    context,
    MaterialPageRoute(builder: (context) => SpesificScreen())
 ); 
}

Upvotes: 1

Related Questions