- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我很难显示我从 FCM 通知控制台发送到我的设备的推送通知。我可以看到设备正在接收通知,因为我可以看到我发送的消息“test8”
Connected to FCM.
%@ [AnyHashable("notification"): {
body = test8;
e = 1;
},
但无论我的应用程序在前台还是后台,我都没有收到通知。
我已将“必需的后台模式 - 应用下载内容以响应推送通知”添加到 info.plist。我的证书是正确的,生成 token 也没有问题。我的应用正在接收通知,但只是不显示它们。
import UIKit
import UserNotifications
import Firebase
import FirebaseInstanceID
import FirebaseMessaging
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// [START register_for_notifications]
if #available(iOS 10.0, *) {
let authOptions : UNAuthorizationOptions = [.Alert, .Badge, .Sound]
UNUserNotificationCenter.currentNotificationCenter().requestAuthorizationWithOptions(
authOptions,
completionHandler: {_,_ in })
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.currentNotificationCenter().delegate = self
// For iOS 10 data message (sent via FCM)
FIRMessaging.messaging().remoteMessageDelegate = self
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
}
application.registerForRemoteNotifications()
// [END register_for_notifications]
FIRApp.configure()
// Add observer for InstanceID token refresh callback.
NSNotificationCenter.defaultCenter().addObserver(self,
selector: #selector(self.tokenRefreshNotification),
name: kFIRInstanceIDTokenRefreshNotification,
object: nil)
return true
}
// [START receive_message]
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject],
fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// TODO: Handle data of notification
// Print message ID.
print("Message ID: \(userInfo["gcm.message_id"]!)")
// Print full message.
print("%@", userInfo)
}
// [END receive_message]
// [START refresh_token]
func tokenRefreshNotification(notification: NSNotification) {
if let refreshedToken = FIRInstanceID.instanceID().token() {
print("InstanceID token: \(refreshedToken)")
}
// Connect to FCM since connection may have failed when attempted before having a token.
connectToFcm()
}
// [END refresh_token]
// [START connect_to_fcm]
func connectToFcm() {
FIRMessaging.messaging().connectWithCompletion { (error) in
if (error != nil) {
print("Unable to connect with FCM. \(error)")
} else {
print("Connected to FCM.")
}
}
}
// [END connect_to_fcm]
func applicationDidBecomeActive(application: UIApplication) {
connectToFcm()
}
// [START disconnect_from_fcm]
func applicationDidEnterBackground(application: UIApplication) {
FIRMessaging.messaging().disconnect()
print("Disconnected from FCM.")
}
// [END disconnect_from_fcm]
}
// [START ios_10_message_handling]
@available(iOS 10, *)
extension AppDelegate : UNUserNotificationCenterDelegate {
// Receive displayed notifications for iOS 10 devices.
func userNotificationCenter(center: UNUserNotificationCenter,
willPresentNotification notification: UNNotification,
withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
// Print message ID.
print("Message ID: \(userInfo["gcm.message_id"]!)")
// Print full message.
print("%@", userInfo)
}
}
extension AppDelegate : FIRMessagingDelegate {
// Receive data message on iOS 10 devices.
func applicationReceivedRemoteMessage(remoteMessage: FIRMessagingRemoteMessage) {
print("%@", remoteMessage.appData)
}
}
// [END ios_10_message_handling]
我一直在尝试自己研究和解决这个问题,但我遇到了问题。任何帮助或建议将不胜感激。
最佳答案
在方法 didRegisterForRemoteNotificationsWithDeviceToken 中,添加以下代码:
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let tokenChars = UnsafePointer<CChar>(deviceToken.bytes)
var tokenString = ""
for i in 0..<deviceToken.length {
tokenString += String(format: "%02.2hhx", arguments: [tokenChars[i]])
}
FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Unknown)
print("tokenString: \(tokenString)")
}
并且不要忘记在功能中启用推送通知。
关于ios10、Swift 3 和 Firebase 推送通知 (FCM),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39729249/
我正在尝试使用 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
我是一名优秀的程序员,十分优秀!