请参阅下面的新发现
尽管遵循Firebase_messaging文档中的配置步骤,但我无法让 FCM 在 iOS 上正常工作。
DATA 消息按预期工作。通知消息根本不显示,无论应用程序是在前台还是后台。
Android 通知按预期工作。此问题仅发生在 iOS 上,并且仅适用于通知消息。
我正在物理设备 (iPhone SE) 上进行测试,即使使用 TestFlight 部署应用程序,我仍然会遇到同样的问题。
void configureFirebase(prefs) async {
try {
await _firebaseMessaging.requestNotificationPermissions();
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async {
print(message);
onMessage(message);
},
// onBackgroundMessage: myBackgroundMessageHandler,
onLaunch: (Map<String, dynamic> message) async {
print("onLaunch: $message");
onMessage(message);
},
onResume: (Map<String, dynamic> message) async {
print("onResume: $message");
onMessage(message);
},
);
} catch (e) {
print(e);
}
}
应用程序编译后,我得到以下信息:
2020-02-09 11:39:34.414043+0100 Runner[236:3651] Configuring the default Firebase app...
2020-02-09 11:39:34.439940+0100 Runner[236:3782] 6.16.0 - [Firebase/Core][I-COR000004] App with name __FIRAPP_DEFAULT does not exist.
2020-02-09 11:39:34.462336+0100 Runner[236:3651] Configured the default Firebase app __FIRAPP_DEFAULT.
2020-02-09 11:39:34.509495+0100 Runner[236:3797] flutter: Observatory listening on http://127.0.0.1:49413/sW_P16TvXjA=/
2020-02-09 11:39:34.530782+0100 Runner[236:3782] 6.16.0 - [Firebase/Messaging][I-FCM001000] FIRMessaging Remote Notifications proxy enabled, will swizzle remote notification receiver handlers. If you'd prefer to manually integrate Firebase Messaging, add "FirebaseAppDelegateProxyEnabled" to your Info.plist, and set it to NO. Follow the instructions at:
https://firebase.google.com/docs/cloud-messaging/ios/client#method_swizzling_in_firebase_messaging
to ensure proper integration.
2020-02-09 11:39:34.535881+0100 Runner[236:3783] 6.16.0 - [Firebase/Analytics][I-ACS023007] Analytics v.60202000 started
2020-02-09 11:39:34.536403+0100 Runner[236:3783] 6.16.0 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see https://help.apple.com/xcode/mac/8.0/#/dev3ec8a1cb4)
2020-02-09 11:39:34.562674+0100 Runner[236:3783] 6.16.0 - [Firebase/Analytics][I-ACS031025] Analytics screen reporting is enabled. Call +[FIRAnalytics setScreenName:setScreenClass:] to set the screen name or override the default screen class name. To disable screen reporting, set the flag FirebaseScreenReportingEnabled to NO (boolean) in the Info.plist
2020-02-09 11:39:34.567991+0100 Runner[236:3782] 6.16.0 - [Firebase/Analytics][I-ACS023012] Analytics collection enabled
如果我在 info.plist 中禁用 FirebaseAppDelegateProxyEnabled,下面是堆栈:
2020-02-09 12:23:03.053017+0100 Runner[290:10393] Configuring the default Firebase app...
2020-02-09 12:23:03.054198+0100 Runner[290:10584] 6.16.0 - [Firebase/Core][I-COR000004] App with name __FIRAPP_DEFAULT does not exist.
2020-02-09 12:23:03.099604+0100 Runner[290:10393] Configured the default Firebase app __FIRAPP_DEFAULT.
2020-02-09 12:23:03.142294+0100 Runner[290:10596] flutter: Observatory listening on http://127.0.0.1:49543/dD-x0XTr2qQ=/
2020-02-09 12:23:03.151748+0100 Runner[290:10583] 6.16.0 - [Firebase/Analytics][I-ACS023007] Analytics v.60202000 started
2020-02-09 12:23:03.152298+0100 Runner[290:10583] 6.16.0 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see https://help.apple.com/xcode/mac/8.0/#/dev3ec8a1cb4)
2020-02-09 12:23:03.153920+0100 Runner[290:10599] 6.16.0 - [Firebase/Analytics][I-ACS025036] App Delegate Proxy is disabled
2020-02-09 12:23:03.166991+0100 Runner[290:10599] 6.16.0 - [Firebase/Analytics][I-ACS031025] Analytics screen reporting is enabled. Call +[FIRAnalytics setScreenName:setScreenClass:] to set the screen name or override the default screen class name. To disable screen reporting, set the flag FirebaseScreenReportingEnabled to NO (boolean) in the Info.plist
2020-02-09 12:23:03.172381+0100 Runner[290:10580] 6.16.0 - [Firebase/Analytics][I-ACS023012] Analytics collection enabled
知道这里会发生什么吗?这是一个非常奇怪的行为,我什至不知道从哪里开始调试。
任何帮助或潜在解决方案的线索将不胜感激。
添加 PyFCM 中使用的消息配置,以防万一这是问题的根源:
push_service = FCMNotification(api_key=fcmServerKey)
testDATA = {
'title': 'Test title',
'body': 'Test body',
'click_action': 'FLUTTER_NOTIFICATION_CLICK',
'otherFields': 'Other fields here',
}
result = push_service.notify_single_device(
registration_id = token,
message_title='Test title',
message_body='Test body',
data_message = testDATA,
time_to_live=0,
delay_while_idle=False,
extra_notification_kwargs=extraKWARGS,
content_available=True
)
新发现:
在 iOS 模拟器中收到通知。但是,它们仅在应用程序处于前台时出现。推送通知不起作用。但是,我读过推送通知在 iOS 模拟器上不起作用,所以这可能就是原因。
考虑到我没有明显的错误,并且已经调试了大约 30 个小时无济于事,我的通知问题有多大可能与这台物理设备(我拥有的 iPhone SE)隔离,这可能是由于 FCM 考虑它离线或它的注册ID无效?
我没有其他 iPhone 可以测试。
该应用程序功能齐全,在所有其他方面都已准备就绪...我是否应该将此视为孤立案例并提交我的应用程序?