GithubHelp home page GithubHelp logo

Comments (6)

pushy avatar pushy commented on August 23, 2024

Hi @calvinmuller,
It appears your project has been updated to version 1.1.1 of the pushy_flutter Dart package. This new version invokes your notification listener in the background, even if your app is not running, allowing you to generate a notification from Dart code.

To update your project to the new Pushy Flutter SDK:

  1. Install version 1.1.1 of our Flutter SDK by editing the pubspec.yaml in the root directory of your project and adding the following under the dependencies section:
pushy_flutter: 1.1.1

Run flutter pub get to fetch the dependency.

Note: Please ensure your Flutter Android project has been updated to Flutter 1.12+ for compatibility with this plugin. Your android/app/src/main/AndroidManifest.xml should contain a <meta-data> attribute labeled flutterEmbedding with a value of 2.

  1. Remove the following lines from your android/app/src/main/AndroidManifest.xml:
<!-- Pushy Notification Receiver -->
<!-- Incoming push notifications will invoke the following BroadcastReceiver -->
<receiver android:name="me.pushy.sdk.flutter.PushReceiver" android:exported="false">
    <intent-filter>
        <!-- Do not modify this -->
        <action android:name="pushy.me" />
    </intent-filter>
</receiver>
  1. Remove any existing Pushy.setNotificationListener((data) => {}) method from your application.

  2. Add the following method to your main.dart file, right after the import statements, and outside any Widget class declaration, to process push notifications in the background via a Flutter background isolate:

// Please place this code in main.dart,
// After the import statements, and outside any Widget class (top-level)

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();
}

Feel free to modify this sample code to suit your own needs.

  1. Call the Pushy.setNotificationListener(backgroundNotificationListener) method after Pushy.listen() to configure the background notification listener:
// Listen for push notifications received
Pushy.setNotificationListener(backgroundNotificationListener);

Please let us know if it resolves the issue.

from pushy-flutter.

pushy avatar pushy commented on August 23, 2024

Closing due to lack of response, feel free to comment to reopen.

from pushy-flutter.

gs-suresh avatar gs-suresh commented on August 23, 2024

@pushy-me I am noticing the same error with Flutter 2.0.6 and pushy_flutter: 2.0.1. I am following instructions from the docs, the only difference is, I am using awesome_notifications instead of the default provided by Pushy. Any idea why this could be happening?

from pushy-flutter.

pushy avatar pushy commented on August 23, 2024

Hi @gs-suresh,
What error are you seeing? Is it the following?

Isolate / notification callback IDs are missing from SharedPreferences

In that case, make sure you are calling Pushy.setNotificationListener(backgroundNotificationListener); and passing in a global function defined in top-level main.dart:

// Please place this code in main.dart,
// After the import statements, and outside any Widget class (top-level)

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();
}

from pushy-flutter.

gs-suresh avatar gs-suresh commented on August 23, 2024

Thanks @pushy-me. It turned out that the function I was using was not a global one. Switching it to a global function fixed the problem for me.

from pushy-flutter.

pushy avatar pushy commented on August 23, 2024

@gs-suresh Glad to hear! 😄

from pushy-flutter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.