- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在从事的一个项目需要使用 FCM 推送通知和消息来控制 VoIP 等。
问题:
我的 iOS 物理设备接收推送通知,但仅当应用程序在后台或关闭时,但不在前台时。此外,它根本不接收任何 fcm 消息(数据)通知,例如只有数据而没有通知标题/正文的消息,即 VoIP 状态消息。
我的设置步骤如下(可以找到我遵循的详细设置和一般流程here):
注册一个(Info.plist
)(参见here)
下载并使用 Xcode 安装 GoogleService-Info.plist
(参见 here)
创建 APNS key 并启用推送通知并将 .p8
文件上传到Firebase(参见 here)
用Swift代码修改:
AppDelegate.swift
代码:
import UIKit
import Flutter
import Firebase // this is added, and (see further down)
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure() //add this before the code below
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
Info.plist
文件功能(后台获取、通知等)
<?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>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
</array>
...
<key>NSCameraUsageDescription</key>
<string>Allows taking a self-portrait profile image or sending a photo while chating</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Allows using your location to make determining country & location picking easier (optional)</string>
<key>NSMicrophoneUsageDescription</key>
<string>Allows using micrphone to chat with someone when making a call</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Allows opening files from gallery</string>
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
<string>bluetooth-central</string>
<string>external-accessory</string>
<string>fetch</string>
<string>location</string>
<string>processing</string>
<string>remote-notification</string>
<string>voip</string>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>FirebaseAppDelegateProxyEnabled</key>
<false/>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
</dict>
</plist>
注意:背景模式如图所示here无法启用,而是我使用一组复选框来启用它们以启用 Background Fetch
等。
实现遵循这些 guidelines :
前台消息:
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
print('Got a message whilst in the foreground!');
...
});
背景信息:
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
await Firebase.initializeApp();
print("Handling a background message: ${message.messageId}");
}
void main() {
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
runApp(MyApp());
}
问题扩展:
调试时,如果 iOS 应用程序处于前台/后台并且测试通知或有效的 VoIP 调用(FCM 数据消息)被发送到设备,应用程序永远不会收到或(也不会命中所需的断点)。
什么会导致应用/iOS 收不到这些 FCM 消息?
从 Firebase 云功能服务发送的示例 VoIP 消息:
// build notification on liked status
const payload = {
token: fcmToken,
data: {
uid: context.auth.uid,
room_id: roomId,
...
},
android: {
priority: 'high',
ttl: 0,
notification: {
priority: 'max',
defaultSound: true,
defaultVibrateTimings: true,
sticky: true,
clickAction: "FLUTTER_NOTIFICATION_CLICK",
}
},
notification: {
title: `Incoming call from ${name}`,
body: `Accept/Reject call`,
// icon: 'your-icon-url', // Add profile image URL here if necessary
// clickAction: 'FLUTTER_NOTIFICATION_CLICK' // required only for onResume or onLaunch callbacks
},
apns: {
payload: {
aps: {
category: "NEW_MESSAGE_CATEGORY",
contentAvailable: true,
}
}
},
headers: {
"apns-push-type": "background",
"apns-priority": "5", // Must be `5` when `contentAvailable` is set to true.
"apns-topic": "io.flutter.plugins.firebase.messaging", // bundle identifier
},
};
await admin.messaging().send(payload);
最佳答案
FCM 不能在 iOS 模拟器上运行,所以问题已经解决了一半。对于物理设备,请查看一些 debugging steps我详细介绍了我工作的图书馆。
推送通知在 iOS 上出错的方式有多种。当您说:应用程序从不接收
时,您的意思是您的 Flutter 应用程序没有收到消息吗?您的设备可能仍在接收它们。
Console.app
,然后开始记录您的物理设备。过滤dasd
进程,你可以看到推送通知相关的日志,看看你的设备是否拒绝了推送通知,没有将它发送到你的应用程序。最有可能的是,您的信息结构存在问题。didReceiveRemoteNotification
方法。 那 表示该消息已被该应用接收。所以你想在前台显示通知?您需要实现 userNotificationCenter(_:willPresent:withCompletionHandler:)
,例如,在 Swift 中:
public func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
if #available(iOS 14.0, *) {
completionHandler(.banner)
} else {
completionHandler(.alert)
}
}
为了在这里为您提供更多帮助,您需要设置委托(delegate)。在上面实现的方法中放置一个断点,以查看它是否实际被调用。
UNUserNotificationCenter.current().delegate = self;
UNUserNotificationCenter.currentNotificationCenter.delegate = self;
如果不设置notification字段,那么需要设置priority为5,push type为background
,contentAvailable
为true
。不幸的是,您错误地使用了 firebase 中的 headers
字段。 apns
对象应如下所示,其中 header 位于 apns
内,因为这些是 apns
特定 header :
apns: {
headers: {
"apns-push-type": "background",
"apns-priority": "5", // Must be `5` when `contentAvailable` is set to true.
"apns-topic": "io.flutter.plugins.firebase.messaging", // bundle identifier
},
payload: {
aps: {
category: "NEW_MESSAGE_CATEGORY",
contentAvailable: true,
}
}
}
如果消息结构错误,您仍然可能在设备上收到错误消息,例如,告诉您优先级为 10(如果未设置,则默认为 10)。因为后台消息(无通知)不会按照文档传递,所以在 Console.app
中您应该看到:
CANCELED: com.apple.pushLaunch.com.example.my-example-app-bundle-id:3D8BB6 at priority 10 <private>!
Additionally, the notification’s POST request should contain the apns-push-type header field with a value of background, and the apns-priority field with a value of 5. - Pushing Background Updates to Your App
这与#2 相同。
关于android - iOS 模拟器或物理设备未收到 FCM 数据消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69055482/
我正在尝试使用 Firebase 云消息传递。我将通知从 Node.js 服务器发送到我注册到通知系统的应用程序。 我的问题是,在 Android 5.1 上,即使我在 nofitification
根据FCM documentation如果 FCM 服务器检测到高优先级消息不会导致用户交互的模式,则高优先级消息可能会被取消优先级。该机制的细节未指定。问题: 这究竟是如何工作的? 检测算法如何收集
更新到最新的 Firebase 后,无法获取所选 的 FCM 注册 token fcmSenderId : FirebaseInstanceId .getInstance()
我想在单个 fcm 请求中向多个设备发送通知。我的通知文本对于所有设备都是相同的。我必须同时向所有用户发送超过 10000 条通知,并且文本是相同的,所以我想以最小的 fcm 请求发送所有通知。我正在
// body 就像这样 { "to": "/topics/NEWS" , "data":{ "extra_information": "This is
当我在浏览器中生成 FCM token 时,我还将其发送到我的服务器,服务器使用 firebase 管理模块将其订阅到主题,如下所示: messaging.subscribeToTopic(token
我正在开发一个应用程序,我想通过 php 实现 FCM 推送通知。 所以我制作了两个java文件:1.FirebaseInstanceID(工作正常并在数据库中正确获取 token )2.Fireba
我正在尝试使用 cordova-plugin-firebasex 向我的cordova 应用程序上的特定用户发送通知这是 cordova-plugin-firebase 的一个 fork 修复和改进。
我正在尝试使用以下方法从我的 iOS-Objective-C 应用发送消息: NSInteger iTime = [NSDate timeIntervalSinceReferenceDate]
我正在尝试为 FCM 实现服务器以向 android/iOS 设备发送通知。 我需要向 android 和 iOS 发送纯数据通知,但 iOS 的后台通知似乎非常不稳定。 (即使该应用程序在前台,我也
我对向手机发送通知的选项感到困惑。我在 Azure 上部署了在 .Net core 中创建的后端。现在,当管理员推出新优惠时,必须将推送通知发送到移动设备。我找到了 3 个很好的替代品。所有人都以自己
我用 POST 设置了一个 REST 客户端 --> https://fcm.googleapis.com/fcm/send 内容类型:应用程序/json 授权: key = JSON 正文: {
我在 Flutter 应用程序中使用 firebase_messaging v9.0.1。关于基于 https://pub.dev/packages/firebase_messaging/exampl
当我使用 Firebase 控制台时,通过激活“高级选项”下的“声音”一切都是完美的,正如 Mouad Abdelghafour AitAli 在接受的答案中所解释的那样 Firebase Push
我已经尝试在 Curl 中使用以下命令使用 Firebase REST Api 发送通知并且它有效: curl -X POST --header "Authorization: key=AIza...
即使 ios 也可以从 fcm 控制台获得通知。 Controller 功能 : public function push(Request $request) { $validator = V
对于通过 XMMP 支持上行和下行消息的服务器端实现,我使用 org.jivesoftware.smack.tcp.XMPPTCPConnection。我从 GCM 迁移到 FCM,现在我的应用服务器
这是我的代码: function sendToken(token) { $.ajax({ url: 'https://iid.googleapis.com/iid/v1/' + token
这是我第一次使用 Flutter 测试 FCM。我检查了一些来自 GitHub 的 SO 问题和文档。 我能够发送通知,当应用程序未运行时它们会被发送。 如果应用程序正在运行或在后台,则消息不可见。
我正在尝试在未接收但他们在调试 apk 中发送/接收很好的发布应用程序中发送 FCM 通知(在用户之间发送消息、好友请求等),我有对此进行了搜索,发现一些对我不起作用的解决方案 像这样,我把它放在 p
我是一名优秀的程序员,十分优秀!