Flutter IOS FCM 推送通知未进入通知栏 [英] Flutter IOS FCM push notification not coming into notification bar
问题描述
我是 Flutter 和 IOS 的新手.我正在为 Android 和 IOS 配置 FCM 推送通知.对于 android,它工作正常.我通过参考此链接完成了
这是我的颤振代码,
class FirebaseNotifications {FirebaseMessaging _firebaseMessaging;SharedPreferences _sharedPreferences;void setUpFirebase() {_firebaseMessaging = FirebaseMessaging();initializeSharedPreferences();firebaseCloudMessaging_Listeners();}void initializeSharedPreferences() 异步 {_sharedPreferences = 等待 SharedPreferences.getInstance();}void firebaseCloudMessaging_Listeners() {if (Platform.isIOS) iOS_Permission();_firebaseMessaging.getToken().then((token) {_sharedPreferences.setString(Preferences.device_token, token);打印('令牌'+令牌);});_firebaseMessaging.configure(onMessage: (Map message) async {print('在消息 $message');},onResume: (Map message) async {print('在简历$message');},onLaunch: (Map message) async {打印('启动$消息');},);}void iOS_Permission() {_firebaseMessaging.requestNotificationPermissions(IosNotificationSettings(声音:真,徽章:真,警报:真));_firebaseMessaging.onIosSettingsRegistered.listen((IosNotificationSettings 设置) {print("已注册的设置:$settings");});}}
万一其他人在未来遇到这种情况,请扩展 这个答案.问题是在 Info.plist
中 FirebaseAppDelegateProxyEnabled
被设置为 bool 而不是字符串,所以:
FirebaseAppDelegateProxyEnabled </false>
变成
FirebaseAppDelegateProxyEnabled <string>0</string>
I am new to Flutter and IOS. I am configuring FCM push notifications for both Android and IOS.For android its working fine.I have done by referring this link https://medium.com/@jun.chenying/flutter-tutorial-part3-push-notification-with-firebase-cloud-messaging-fcm-2fbdd84d3a5e . For IOS, if the app is opened and if I send FCM from Firebase Console at the same time , Flutter on message is called (See the screenshot , logs are there) . But if I close the app , notification is not coming to notification bar but I am receiving in Android App, I don't know where is the problem , Problem with Apple Profiles or Flutter .
IOS Build Settings and Signing & Capabilities
Here is my code in flutter,
class FirebaseNotifications {
FirebaseMessaging _firebaseMessaging;
SharedPreferences _sharedPreferences;
void setUpFirebase() {
_firebaseMessaging = FirebaseMessaging();
initializeSharedPreferences();
firebaseCloudMessaging_Listeners();
}
void initializeSharedPreferences() async {
_sharedPreferences = await SharedPreferences.getInstance();
}
void firebaseCloudMessaging_Listeners() {
if (Platform.isIOS) iOS_Permission();
_firebaseMessaging.getToken().then((token) {
_sharedPreferences.setString(Preferences.device_token, token);
print('Token'+token);
});
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print('on message $message');
},
onResume: (Map<String, dynamic> message) async {
print('on resume $message');
},
onLaunch: (Map<String, dynamic> message) async {
print('on launch $message');
},
);
}
void iOS_Permission() {
_firebaseMessaging.requestNotificationPermissions(
IosNotificationSettings(sound: true, badge: true, alert: true));
_firebaseMessaging.onIosSettingsRegistered
.listen((IosNotificationSettings settings) {
print("Settings registered: $settings");
});
}
}
In case anyone else runs into this in the future, to expand on this answer. The issue was that in the Info.plist
FirebaseAppDelegateProxyEnabled
was set to bool rather than a string so:
<key>FirebaseAppDelegateProxyEnabled</key>
</false>
becomes
<key>FirebaseAppDelegateProxyEnabled</key>
<string>0</string>
这篇关于Flutter IOS FCM 推送通知未进入通知栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!