【问题标题】:Flutter with firebase_messaging - how to custom message on permission dialog?Flutter with firebase_messaging - 如何在权限对话框中自定义消息?
【发布时间】:2020-01-22 13:24:08
【问题描述】:

我正在使用 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!

提前致谢!

【问题讨论】:

标签: ios firebase flutter


【解决方案1】:

在我的情况下,我更新了 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;
});

问题解决了。

【讨论】:

    【解决方案2】:

    首次更新 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,
      );
    } 
    

    }

    【讨论】:

    猜你喜欢
    • 2016-01-20
    • 1970-01-01
    • 1970-01-01
    • 2019-03-31
    • 2015-11-12
    • 2020-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多