Skip to content

Instantly share code, notes, and snippets.

@yshean
Last active November 5, 2021 14:40
Show Gist options
  • Save yshean/b33cc75512b27d50c95fcabfe4b6aa05 to your computer and use it in GitHub Desktop.
Save yshean/b33cc75512b27d50c95fcabfe4b6aa05 to your computer and use it in GitHub Desktop.
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");
},
);
}
}
@MatildaZhou
Copy link

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