[英]Flutter with firebase_messaging - how to custom message on permission dialog?
我正在使用 fcm 和 firebase_messaging 向 flutter 應用程序發送推送通知,並希望在執行 FirebaseMessaging().requestNotificationPermissions 時為 ios 遠程通知自定義權限消息。
現在我在下面有權限對話框
如何自定義“”“想向您發送通知”、“通知可能包括警報、聲音和圖標……”和“不允許/允許”? 有人知道嗎?
和我的代碼
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
await _firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(
sound: true, badge: true, alert: true));
await _firebaseMessaging.onIosSettingsRegistered.listen((settings) {
debugPrint('Settings registered: $settings');
});
這是我的flutter doctor -v
結果
[✓] 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!
提前致謝!
首先更新您的 pubspec.yaml 文件中最新的 firebase 消息傳遞依賴項
firebase_messaging: ^9.1.0
然后創建一個 firebase 消息傳遞實例
final FirebaseMessaging firebaseMessaging = FirebaseMessaging.instance;
然后請求權限
Future initialize(context) async {
if (Platform.isIOS) {
firebaseMessaging.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
}
}
在我的例子中,我更新了 firebase 依賴項 firebase_messaging: ^10.0.2 並替換
_fcm.requestNotificationPermissions(const IosNotificationSettings())
到
_fcm.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
但我們將不得不改變
_fcm.configure()
同樣,用下面的代碼改變它。
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
RemoteNotification _notification = message.notification;
AndroidNotification _android = message.notification?.android;
});
問題解決了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.