pushy / pushy-flutter

The official Pushy SDK for Flutter apps.
Apache License 2.0
21 stars 19 forks source link

iOS device - "Pushy: Error retrieving handle for Flutter callbacks" #47

Closed GirishVerm closed 2 years ago

GirishVerm commented 2 years ago

iOS device unable to listen for notifications when setNotificationListener is used.

I am not using firebase-messaging or any other push notification service, what's odd is my code was working yesterday but isn't working today with a similar setup.

I have set up my main file according to the documentation but its not working. So I set a notification listener in my home page that responds with error "Pushy: Error retrieving handle for Flutter callbacks".

SETUP in MAIN FILE ` void backgroundNotificationListener(Map<String, dynamic> data) { // Print notification payload data print('Received notification: $data');

// Notification title String notificationTitle = 'MyApp';

// Attempt to extract the "message" property from the payload: {"message":"Hello World!"} String notificationText = data['message'] ?? 'Hello World!';

// Android: Displays a system notification // iOS: Displays an alert dialog Pushy.notify(notificationTitle, notificationText, data);

// Clear iOS app badge number Pushy.clearBadge(); }

void main() async {

WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); Pushy.toggleInAppBanner(true);

//this listener doesn't respond at all, no errors and no notifications. Pushy.setNotificationListener(backgroundNotificationListener);

//initLogic takes me to home page runApp(initLogic());

}`

SETUP in HOME PAGE

` @override void initState() { print("listening"); Pushy.listen();

//here the setNotificationListener prints "Pushy: Error retrieving handle for Flutter callbacks" Pushy.setNotificationListener((data) { print('Received notification: $data');

  // Notification title
  String notificationTitle = 'MyApp';

  // Attempt to extract the "message" property from the payload: {"message":"Hello World!"}
  String notificationText = data['message'] ?? 'Hello World!';

  // Android: Displays a system notification
  // iOS: Displays an alert dialog
  Pushy.notify(notificationTitle, notificationText, data);

  // Clear iOS app badge number
  Pushy.clearBadge();
});

//...other stuff in initState

}`

pushy commented 2 years ago

Hi @GirishVerm, We'd be glad to assist.

It is currently not possible to call Pushy.setNotificationListener() outside of the lib/main.dart file. It appears you are trying to call this method from within your home page widget. This is unsupported.

Please find a sample supported implementation in the Flutter Demo app's lib/main.dart.