我正在努力显示我从FCM通知控制台发送到我的设备的推送通知.我可以看到设备正在接收通知,因为我可以看到我发送的消息"test8"
Connected to FCM.
%@ [AnyHashable("notification"): {
body = test8;
e = 1;
},
Run Code Online (Sandbox Code Playgroud)
但是,如果我的应用程序位于前台或后台并不显示通知,则无关紧要.
我已将"必需的后台模式 - 应用程序下载内容以响应推送通知"添加到info.plist.我的证书是正确的,我没有生成令牌的问题.我的应用程序正在接收通知,但只是没有显示它们.
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 = …Run Code Online (Sandbox Code Playgroud)