Last active
November 5, 2021 14:40
-
-
Save yshean/b33cc75512b27d50c95fcabfe4b6aa05 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:firebase_messaging/firebase_messaging.dart'; | |
class PushNotificationService { | |
final FirebaseMessaging _fcm; | |
PushNotificationService(this._fcm); | |
Future initialise() async { | |
if (Platform.isIOS) { | |
_fcm.requestNotificationPermissions(IosNotificationSettings()); | |
} | |
// If you want to test the push notification locally, | |
// you need to get the token and input to the Firebase console | |
// https://console.firebase.google.com/project/YOUR_PROJECT_ID/notification/compose | |
String token = await _fcm.getToken(); | |
print("FirebaseMessaging token: $token"); | |
_fcm.configure( | |
onMessage: (Map<String, dynamic> message) async { | |
print("onMessage: $message"); | |
}, | |
onLaunch: (Map<String, dynamic> message) async { | |
print("onLaunch: $message"); | |
}, | |
onResume: (Map<String, dynamic> message) async { | |
print("onResume: $message"); | |
}, | |
); | |
} | |
} |
_fcm.requestNotificationPermissions and _fcm.configure are undefined. Using flutter_messaging 10.0.3, also IosNotificationSettings doesn't resolve to any library.
https://firebase.flutter.dev/docs/migration/ There is something updated.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If the application is closed, the notification does not appear