當我使用顫振在 iOS 上開發時,無法收到來自 firebase 的通知
我已授予許可并使用郵遞員進行測驗。
首先,我會得到令牌
Restarted application in 516ms.
flutter: User granted permission
flutter: This token is eWQJLcN1zEQ_rQ79sBqXI6:APA91bHMnuhkPaf8JpcTbLQavxqq5erUIeRTQYPv9NAhsdfasdfasdaDSA0BTXgVb2RseAmUsi5uAa5SDvGWA7wgIcWPP5xDqTyo4s3xEdWkhHoQc77G59GGZptafaxNIW5QG
Secode:當我去郵遞員測驗時,我得到了成功
{
"multicast_id": 2305740741419558081,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "0:1654957148235526'34e82c2734e82c"
}
]
}
但我仍然無法得到任何通知。
哪里有問題?
這是代碼。
late int _totalNotifications;
late final FirebaseMessaging _messaging;
PushNotification? _notificationInfo;
void requestAndRegisterNotification() async {
await Firebase.initializeApp();
_messaging = FirebaseMessaging.instance;
FirebaseMessaging.onBackgroundMessage(_firebaseMessageingBackgroundHandler);
NotificationSettings settings = await _messaging.requestPermission(
alert: true,
badge: true,
provisional: false,
sound: true,
);
if (settings.authorizationStatus == AuthorizationStatus.authorized) {
print('User granted permission');
String? token = await _messaging.getToken();
print('This token is ' token!);
FirebaseMessaging.onMessage.listen(
(RemoteMessage message) {
PushNotification notification = PushNotification(
title: message.notification?.title,
body: message.notification?.body,
);
setState(() {
_notificationInfo = notification;
_totalNotifications ;
});
if (_notificationInfo != null) {
showSimpleNotification(
Text(_notificationInfo!.title!),
leading:
NotificationBadge(totalNotification: _totalNotifications),
subtitle: Text(_notificationInfo!.body!),
background: Colors.cyan.shade700,
duration: Duration(seconds: 2),
);
}
},
);
} else {
print('User decliend or has not appected permission');
}
}
@override
void initState() {
super.initState();
requestAndRegisterNotification();
_totalNotifications = 0;
}
uj5u.com熱心網友回復:
如果您使用的是 iOS 模擬器,則無法接收推送通知。你需要有一個真實的設備來測驗這個。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/489327.html
下一篇:未捕獲的FirebaseError:查詢無效。您不能在呼叫orderBy()之前呼叫startAt()或startAfter()
