英文:
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
我的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());
}
我尝试等待了很长时间,但没有一条通知消息到达我。
附言 - 是的,我在真实设备上测试
告诉我我做错了什么?为什么我没有收到测试消息?
附言:显然需要澄清,我试图发送消息不仅仅是给一个设备,而是给一切在应用程序启动时收到发送通知请求的设备。
我的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 Google Service Info -
<?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>
My main.dart code is
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
// If you'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("Handling background message : ${message.messageId}");
}
future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
name: 'eco-city-deeplink',
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('User granted permission');
} else if (settings.authorizationStatus == AuthorizationStatus.provisional) {
print('User granted temporary permission');
} else {
print('User denied or did not accept permission');
}
//Messages in the foreground
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
print('Got a message while in the foreground!');
print('Message data: ${message.data}');
if (message.notification != null) {
print('The message also contained a notification: ${message.notification}');
}
});
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
runApp(MyApp());
}
Settings cloud messaging in firebase -
my profiles in developer.apple -
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
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]?
) -> 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('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
答案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]?
) -> Bool {
FirebaseApp.configure()
GeneratedPluginRegistrant.register(with: self)
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论