【问题标题】:IOS Device not receiving notification from firebaseIOS 设备未收到来自 firebase 的通知
【发布时间】:2021-12-10 06:52:29
【问题描述】:

我正在尝试向我的 Flutter 应用发送推送通知,Android 部分工作正常,但 iOS 设备没有收到推送通知(我创建了 APN 证书,在我的另一个应用中工作正常)。

这是我的配置

ma​​in.dart

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  SharedPreferences prefs = await SharedPreferences.getInstance();
  await Firebase.initializeApp();
  String? logged =
      prefs.getString('uid') == null || prefs.getString('uid') == ''
          ? null
          : prefs.getString('uid');

  initializeDateFormatting();
  Intl.defaultLocale = 'tr';
  listenChanges();
  AwesomeNotifications().initialize(
      // set the icon to null if you want to use the default app icon
      'resource://drawable/res_app_icon',
      []);

  FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
  // Create the initialization for your desired push service here

  runApp(MyApp(
    logged: logged,
  ));
}

class MyApp extends StatefulWidget {
  MyApp({required this.logged});

  String? logged;

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Greatr',
      theme: whiteTheme,
      home: widget.logged != null ? SplashScreen() : Onboarding(),
    );
  }
}

Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  AwesomeNotifications().createNotificationFromJsonData(message.data);
}

这与我的工作示例相同。

AppDelegate.swift

import UIKit
import Flutter
import Firebase
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
     FirebaseApp.configure()
    GeneratedPluginRegistrant.register(with: self)
   
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

还启用了推送通知和 BackgroundModes(后台获取和远程通知)

尝试解决这个问题 2-3 天并尝试了所有解决方案,仍然没有通知,知道如何解决它吗?

版本

awesome_notifications: ^0.0.6+10
  firebase_core: "^1.0.4"
  firebase_messaging: "^9.1.2"

【问题讨论】:

    标签: firebase flutter push-notification firebase-cloud-messaging


    【解决方案1】:

    来自火力基地documentation
    将您的 APNs 身份验证密钥上传到 Firebase。如果您还没有 APNs 身份验证密钥,请确保在 Apple Developer Member Center 中创建一个。

    在 Firebase 控制台的项目中,选择齿轮图标,选择项目设置,然后选择云消息传递选项卡。

    在 iOS 应用配置下的 APNs 身份验证密钥中,单击上传按钮。

    浏览到您保存密钥的位置,选择它,然后单击打开。添加密钥的密钥 ID(在Apple Developer Member Center 中提供)并点击​​上传。

    【讨论】:

    • 已经这样做了。我的密钥在我的另一个应用程序中运行良好
    • 每个bundle ID都需要自己的APN证书
    • 我正在使用 APN 身份验证密钥,它在我的一个应用程序中运行良好,根据这个主题,我不需要另一个,stackoverflow.com/questions/61747419/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-09
    • 2017-05-05
    • 2016-09-17
    • 1970-01-01
    • 2018-06-21
    • 1970-01-01
    • 2019-04-19
    相关资源
    最近更新 更多