Messages not coming to iPhone via FCM.

huangapple go评论64阅读模式
英文:

Messages not coming to iPhone via FCM

问题

I'm here to provide translations, so here is the translation of the text you provided:

"我正在尝试发送一条消息,但不幸的是,我没有收到任何通知,我尝试了三次,但没有一次成功到达我的手机。

以下是可能对您有用的所有信息 -
包标识 - com.atlas.ecoCity

我的后台模型是 -
Messages not coming to iPhone via FCM.

我的Google服务信息 -

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CLIENT_ID</key>
	<string>753631636992-qg1l63ttslllc8kgug0j0rn6gpk3hqkq.apps.googleusercontent.com</string>
	<key>REVERSED_CLIENT_ID</key>
	<string>com.googleusercontent.apps.753631636992-qg1l63ttslllc8kgug0j0rn6gpk3hqkq</string>
	<key>ANDROID_CLIENT_ID</key>
	<string>753631636992-n9lpns306gu7q44f5lch8cokshaa1juk.apps.googleusercontent.com</string>
	<key>API_KEY</key>
	<string>AIzaSyAxFNhRGma2x9xkAhgLwX0pw--CNiiIYGg</string>
	<key>GCM_SENDER_ID</key>
	<string>753631636992</string>
	<key>PLIST_VERSION</key>
	<string>1</string>
	<key>BUNDLE_ID</key>
	<string>com.atlas.ecoCity</string>
	<key>PROJECT_ID</key>
	<string>eco-city-7f66a</string>
	<key>STORAGE_BUCKET</key>
	<string>eco-city-7f66a.appspot.com</string>
	<key>IS_ADS_ENABLED</key>
	<false></false>
	<key>IS_ANALYTICS_ENABLED</key>
	<false></false>
	<key>IS_APPINVITE_ENABLED</key>
	<true></true>
	<key>IS_GCM_ENABLED</key>
	<true></true>
	<key>IS_SIGNIN_ENABLED</key>
	<true></true>
	<key>GOOGLE_APP_ID</key>
	<string>1:753631636992:ios:21e0bc6953671795b032e5</string>
</dict>
</plist>

我的main.dart代码是

Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
   // 如果您要在后台使用其他Firebase服务,例如Firestore,
   // 确保在使用其他Firebase服务之前调用`initializeApp`。
   await Firebase.initializeApp();

   print("处理后台消息:${message.messageId}");
}

Future<void> main() async {
   WidgetsFlutterBinding.ensureInitialized();

   await Firebase.initializeApp(
     name: 'eco-city-deeplink',
     options: DefaultFirebaseOptions.currentPlatform,
   );

   // 请求权限 -
   FirebaseMessaging messaging = FirebaseMessaging.instance;

   NotificationSettings settings = await messaging.requestPermission(
     alert: true,
     announcement: false,
     badge: true,
     carPlay: false,
     criticalAlert: false,
     provisional: false,
     sound: true,
   );

   if (settings.authorizationStatus == AuthorizationStatus.authorized) {
     print('用户授予权限');
   } else if (settings.authorizationStatus == AuthorizationStatus.provisional) {
     print('用户授予临时权限');
   } else {
     print('用户拒绝或未接受权限');
   }

   // 前台消息
   FirebaseMessaging.onMessage.listen((RemoteMessage message) {
     print('在前台收到消息!');
     print('消息数据:${message.data}');

     if (message.notification != null) {
       print('消息还包含通知:${message.notification}');
     }
   });

   FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);

   runApp(MyApp());
}

在Firebase中设置云消息推送 -
Messages not coming to iPhone via FCM.

在developer.apple中的密钥 - Messages not coming to iPhone via FCM.

在developer.apple中的配置文件 - Messages not coming to iPhone via FCM.

我尝试等待了很长时间,但没有一条通知消息到达我。
附言 - 是的,我在真实设备上测试

还有我的测试消息 - Messages not coming to iPhone via FCM.

告诉我我做错了什么?为什么我没有收到测试消息?

附言:显然需要澄清,我试图发送消息不仅仅是给一个设备,而是给一切在应用程序启动时收到发送通知请求的设备。

我的AppDelegate.swift -

import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}
英文:

I'm trying to send a message, but unfortunately I don't receive any notification, I tried three attempts, but none of them reached my phone

Here is all the information that might be useful to you -
bundle id - com.atlas.ecoCity

my background model is -
Messages not coming to iPhone via FCM.

my Google Service Info -

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE plist PUBLIC &quot;-//Apple//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;
&lt;plist version=&quot;1.0&quot;&gt;
&lt;dict&gt;
	&lt;key&gt;CLIENT_ID&lt;/key&gt;
	&lt;string&gt;753631636992-qg1l63ttslllc8kgug0j0rn6gpk3hqkq.apps.googleusercontent.com&lt;/string&gt;
	&lt;key&gt;REVERSED_CLIENT_ID&lt;/key&gt;
	&lt;string&gt;com.googleusercontent.apps.753631636992-qg1l63ttslllc8kgug0j0rn6gpk3hqkq&lt;/string&gt;
	&lt;key&gt;ANDROID_CLIENT_ID&lt;/key&gt;
	&lt;string&gt;753631636992-n9lpns306gu7q44f5lch8cokshaa1juk.apps.googleusercontent.com&lt;/string&gt;
	&lt;key&gt;API_KEY&lt;/key&gt;
	&lt;string&gt;AIzaSyAxFNhRGma2x9xkAhgLwX0pw--CNiiIYGg&lt;/string&gt;
	&lt;key&gt;GCM_SENDER_ID&lt;/key&gt;
	&lt;string&gt;753631636992&lt;/string&gt;
	&lt;key&gt;PLIST_VERSION&lt;/key&gt;
	&lt;string&gt;1&lt;/string&gt;
	&lt;key&gt;BUNDLE_ID&lt;/key&gt;
	&lt;string&gt;com.atlas.ecoCity&lt;/string&gt;
	&lt;key&gt;PROJECT_ID&lt;/key&gt;
	&lt;string&gt;eco-city-7f66a&lt;/string&gt;
	&lt;key&gt;STORAGE_BUCKET&lt;/key&gt;
	&lt;string&gt;eco-city-7f66a.appspot.com&lt;/string&gt;
	&lt;key&gt;IS_ADS_ENABLED&lt;/key&gt;
	&lt;false&gt;&lt;/false&gt;
	&lt;key&gt;IS_ANALYTICS_ENABLED&lt;/key&gt;
	&lt;false&gt;&lt;/false&gt;
	&lt;key&gt;IS_APPINVITE_ENABLED&lt;/key&gt;
	&lt;true&gt;&lt;/true&gt;
	&lt;key&gt;IS_GCM_ENABLED&lt;/key&gt;
	&lt;true&gt;&lt;/true&gt;
	&lt;key&gt;IS_SIGNIN_ENABLED&lt;/key&gt;
	&lt;true&gt;&lt;/true&gt;
	&lt;key&gt;GOOGLE_APP_ID&lt;/key&gt;
	&lt;string&gt;1:753631636992:ios:21e0bc6953671795b032e5&lt;/string&gt;
&lt;/dict&gt;
&lt;/plist&gt;

My main.dart code is

Future&lt;void&gt; _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
   // If you&#39;re going to use other Firebase services in the background, such as Firestore,
   // make sure you call `initializeApp` before using other Firebase services.
   await Firebase.initializeApp();

   print(&quot;Handling background message : ${message.messageId}&quot;);
}

future&lt;void&gt; main() async {
   WidgetsFlutterBinding.ensureInitialized();

   await Firebase.initializeApp(
     name: &#39;eco-city-deeplink&#39;,
     options: DefaultFirebaseOptions.currentPlatform,
   );

   //Request for permission -
   FirebaseMessaging messaging = FirebaseMessaging.instance;

   NotificationSettings settings = await messaging.requestPermission(
     alert: true
     announcement: false
     badge: true
     carPlay: false
     criticalAlert: false
     provisional: false
     sound: true
   );

   if (settings.authorizationStatus == AuthorizationStatus.authorized) {
     print(&#39;User granted permission&#39;);
   } else if (settings.authorizationStatus == AuthorizationStatus.provisional) {
     print(&#39;User granted temporary permission&#39;);
   } else {
     print(&#39;User denied or did not accept permission&#39;);
   }

   //Messages in the foreground
   FirebaseMessaging.onMessage.listen((RemoteMessage message) {
     print(&#39;Got a message while in the foreground!&#39;);
     print(&#39;Message data: ${message.data}&#39;);

     if (message.notification != null) {
       print(&#39;The message also contained a notification: ${message.notification}&#39;);
     }
   });

   FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);

   runApp(MyApp());
}

Settings cloud messaging in firebase -
Messages not coming to iPhone via FCM.

my key in developer.apple - Messages not coming to iPhone via FCM.

my profiles in developer.apple - Messages not coming to iPhone via FCM.

I tried to wait a very long time, but not a single notification came to me.
PS - Yes, I'm testing on a real device

And my testing messaging - Messages not coming to iPhone via FCM.

Tell me what I did wrong? Why am I not receiving test messages?

PS: Apparently, it should be clarified, I'm trying to send not to one device, but to everything that received a request to send notifications when the application starts

my AppDelegate.swift -

import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -&gt; Bool {
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

答案1

得分: 3

just for the future, try to put [redacted] or something at the place where your API-key is in the config. This would prevent someone else from stealing it and sending messages on your behalf or worse.

Would like to ask, if you registered your phone to FCM by calling the getToken function?
https://firebase.google.com/docs/cloud-messaging/flutter/client?hl=en#access_the_registration_token

// It requests a registration token for sending messages to users from your App server or other trusted server environment.
String? token = await messaging.getToken();

if (kDebugMode) {
print('Registration Token=$token');
}

This call would print the token in the console while debugging. It is useful, if you want to target your phone directly, but also necessary to make your phone "targetable" at all.

Please let me know if this fixes your problem.

Best regards

英文:

just for the future, try to put [redacted] or something at the place where your API-key is in the config. This would prevent someone else from stealing it and sending messages on your behalf or worse.

Would like to ask, if you registered your phone to FCM by calling the getToken function?
https://firebase.google.com/docs/cloud-messaging/flutter/client?hl=en#access_the_registration_token

// It requests a registration token for sending messages to users from your App server or other trusted server environment.
String? token = await messaging.getToken();

if (kDebugMode) {
  print(&#39;Registration Token=$token&#39;);
}

This call would print the token in the console while debugging. It is useful, if you want to target your phone directly, but also necessary to make your phone "targetable" at all.

Please let me know if this fixes your problem.

Best regards

答案2

得分: 0

请检查您的 AppDelegate.swift 配置文件中的以下部分:

import UIKit
import Flutter
import Firebase

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    FirebaseApp.configure()
    GeneratedPluginRegistrant.register(with: self)
    if #available(iOS 10.0, *) {
      UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
    }
   
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

我已为您翻译并返回了代码部分。

英文:

please check this configuration for your AppDelegate.swift

import UIKit
import Flutter
import Firebase

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -&gt; Bool {
    FirebaseApp.configure()
    GeneratedPluginRegistrant.register(with: self)
    if #available(iOS 10.0, *) {
      UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
      }
   
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

huangapple
  • 本文由 发表于 2023年4月19日 15:50:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76051950.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定