简体   繁体   English

扑火的Firebase消息传递,iOS应用程序未收到令牌

[英]Flutter firebase messaging, ios application don't receive token

I have configured firebase messaging in flutter app. 我已经在Flutter应用中配置了Firebase消息传递。 It use firebase messaging plugin . 它使用Firebase消息传递插件 I have configured according to "iOS Integration" section from readme. 我已经根据自述文件的“ iOS集成”部分进行了配置。 Firebase is inited in main.dart Firebase在main.dart中被main.dart

void main() async {
  final FirebaseMessaging _firebaseMessaging = new FirebaseMessaging();
  _firebaseMessaging.requestNotificationPermissions();
  _firebaseMessaging.configure(onMessage: processMessage,
      onLaunch: processLaunch,
      onResume: processResume);
  String token = await _firebaseMessaging.getToken();
  print("fcm token is: $token");
  runApp(TestApp());
}

Future<dynamic> processMessage(Map<String, dynamic> map) async {
  print("received message:");
  print(map);
}

Future<dynamic> processLaunch(Map<String, dynamic> map) async {
  print("processing launch");
  print(map);
}

Future<dynamic> processResume(Map<String, dynamic> map) async {
  print("processing resume");
  print(map);
}

The problem is app don't receive token. 问题是应用程序未收到令牌。 So I deploy application to physical device, application starts, but don't see any output related to fcm, and ui not shown. 因此,我将应用程序部署到物理设备,应用程序启动,但是没有看到与fcm相关的任何输出,并且未显示ui。 I see following logs in IDEA: 我在IDEA中看到以下日志:

5.10.0 - [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) to your application initialization. Read more: .
5.10.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

Where can be problem? 哪里有问题?

It started to work when I moved firebase code to TestApp , seems like main.dart is wrong place for fcm code. 当我将Firebase代码移至TestApp ,它开始工作,似乎main.dart是fcm代码的错误位置。 I placed it inside initState . 我将其放在initState

As of October 11 2018, the getToken implementation is faulty (see issues 17699 and 20378 ). 作为二○一八年十月一十一日中, getToken实现故障(见问题1769920378 )。

There's a pull request to fix it, but it's still pending. 有一个修复请求拉动请求 ,但仍在处理中。

For now, in order to avoid problems with getToken , I would suggest listening to onTokenRefresh (that's what I do). 现在,为了避免问题getToken ,我建议听onTokenRefresh (这是我做的)。

I didn't test the code below, but it's just an example of how you would have to adapt your code. 我没有测试下面的代码,但这只是您如何修改代码的示例。

String _token;

void main() async {
  final FirebaseMessaging _firebaseMessaging = new FirebaseMessaging();
  _firebaseMessaging.requestNotificationPermissions();

  Stream<String> fcmStream = _firebaseMessaging.onTokenRefresh;
  fcmStream.listen((token) {
    // saveToken(token);
    print("fcm token is: $token");
    _token = token;     
  });

  _firebaseMessaging.configure(onMessage: processMessage,
      onLaunch: processLaunch,
      onResume: processResume);

  runApp(TestApp());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 适用于iOS的Firebase云消息传递:不接收来自POST请求的通知(仅来自作曲家工具) - Firebase cloud messaging for iOS: don't receive notifications from POST request (only from composer tool) 为什么我的 flutter 应用在 iOS 上运行时没有使用 Firebase 云消息接收通知? - Why my flutter app doesn't receive notifications using Firebase Cloud Messaging when running on iOS? Firebase 云消息推送通知不再出现在 iOS 上 - Firebase Cloud Messaging Push Notificartions don't arrive on iOS anymore Flutter Firebase 消息(推送通知)不适用于 iOS 在现有应用程序中 - Flutter Firebase Messaging (Push Notifications) Not Working for iOS in an Already Existing Application Google Cloud Messaging:iOS App处于后台时不会收到提醒 - Google Cloud Messaging: don't receive alerts when iOS App is in background FireBase iOS消息传递,无法获取APNS令牌 - FireBase iOS Messaging, fails to fetch APNS Token iOS SwuftUI - 获取 firebase 消息传递用户令牌 - iOS SwuftUI - get firebase messaging user token Flutter Firebase Messaging iOS处理程序未调用 - Flutter Firebase Messaging iOS Handlers not called Flutter [firebase_messaging] IOS 构建错误 - Flutter [firebase_messaging] IOS Build Error Flutter pod 安装错误,在 ios 上出现 firebase 消息 - Flutter pod install error with firebase messaging on ios
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM