【发布时间】:2021-12-10 06:52:29
【问题描述】:
我正在尝试向我的 Flutter 应用发送推送通知,Android 部分工作正常,但 iOS 设备没有收到推送通知(我创建了 APN 证书,在我的另一个应用中工作正常)。
这是我的配置
main.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