Разрешения запрашиваются в приложении как таковые:
Код: Выделить всё
void requestAndRegisterNotification() async {
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
NotificationSettings settings =
await FirebaseMessaging.instance.requestPermission(
alert: true,
badge: true,
provisional: false,
sound: true,
);
if (settings.authorizationStatus == AuthorizationStatus.authorized) {
print('User granted permission');
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
print(
'Message title: ${message.notification?.title}, body: ${message.notification?.body}, data: ${message.data}');
});
} else {
print('User declined or has not accepted permission');
}
}
Сертификат на портале разработчика выглядит так: это: Сертификат. Идентификатор выглядит следующим образом: Идентификатор. Ключ для push-уведомления выглядит следующим образом: Key. APN Firebase Cloud Messasing выглядят следующим образом: Firebase.
Файл AppDelegate в Runner был изменен следующим образом:
Код: Выделить всё
import UIKit
import Flutter
import Firebase
import FirebaseMessaging
@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)
}
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
}
}
Подробнее здесь: https://stackoverflow.com/questions/737 ... -an-alread
Мобильная версия