Reputation: 47
I'm using fcm and firebase_messaging to send push notification to flutter app, and want to custom permission message when executing FirebaseMessaging().requestNotificationPermissions for ios remote notification.
Now I have permission dialog below
How to custom '"" Would Like to Send You Notifications', 'Notifications may include alerts, sounds, and icon...', and 'Don't Allow/Allow'? Does anyone any idea?
and my code
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
await _firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(
sound: true, badge: true, alert: true));
await _firebaseMessaging.onIosSettingsRegistered.listen((settings) {
debugPrint('Settings registered: $settings');
});
Here's my flutter doctor -v
result
[✓] Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.15.1 19B88, locale ja-JP)
• Flutter version 1.12.13+hotfix.5 at /usr/local/bin/flutter
• Framework revision 27321ebbad (6 weeks ago), 2019-12-10 18:15:01 -0800
• Engine revision 2994f7e1e6
• Dart version 2.7.0
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/shunmanabe/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.3.1, Build version 11C504
• CocoaPods version 1.8.4
[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 42.1.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] VS Code (version 1.41.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.7.1
[✓] Connected device (1 available)
• iPhone 11 • 4B5E0CE0-8D25-49CC-BEBA-0BDE35991977 • ios •
com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator)
• No issues found!
Thanks in advance!
Upvotes: 3
Views: 14238
Reputation: 477
Don't use the method included with the Firebase Messaging to request the permission. In my app I use a plugin to detect the status of the permissions I need. If the permissions are missing I show a custom bottom sheet explaining why I need the permission. When the user clicks the button grant permission inside my bottom sheet, then I launch the runtime permission defined by Android (using the same plugin). Just check pub.dev friend.
Upvotes: 0
Reputation: 69
In my case i updated the firebase dependency firebase_messaging: ^10.0.2 and replace
_fcm.requestNotificationPermissions(const IosNotificationSettings())
to
_fcm.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
but we will have to change
_fcm.configure()
as well, change it with below code.
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
RemoteNotification _notification = message.notification;
AndroidNotification _android = message.notification?.android;
});
and problem solved.
Upvotes: 6
Reputation: 979
first update to the latest firebase messaging dependency in your pubspec.yaml file
firebase_messaging: ^9.1.0
then create an instance of firebase messaging
final FirebaseMessaging firebaseMessaging = FirebaseMessaging.instance;
then request for the permission
Future initialize(context) async {
if (Platform.isIOS) {
firebaseMessaging.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
}
}
Upvotes: 12