Firebase远程通知不能接收? [英] Firebase Remote Notifications Not Receiving?

查看:597
本文介绍了Firebase远程通知不能接收?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过云端消息从我的Firebase控制台发送远程通知,但我的手机没有收到任何警报。我已经将我的证书上传到Firebase,并使用Firebase教程提供的默认代码接收通知。



这是我的证书图片,显示我已经创建了它


这是我在其中实现的代码。
class AppDelegate:UIResponder,UIApplicationDelegate {

  var window:UIWindow? 

覆盖init(){
FIRApp.configure()
FIRDatabase.database()。persistenceEnabled = true
}

func应用程序(application:UIApplication,didFinishLaunchingWithOptions launchOptions:[NSObject:AnyObject]?) - > Bool {
//在应用程序启动后替代自定义点。
let notificationTypes:UIUserNotificationType = [UIUserNotificationType.Alert,UIUserNotificationType.Badge,UIUserNotificationType.Sound]
let notificationSettings = UIUserNotificationSettings(forTypes:notificationTypes,categories:nil)
application.registerForRemoteNotifications()
application.registerUserNotificationSettings(notificationSettings)

return FBSDKApplicationDelegate.sharedInstance()。application(application,didFinishLaunchingWithOptions:launchOptions)
}

func application(application:UIApplication ,
openURL url:NSURL,
sourceApplication:String ?,
annotation:AnyObject) - > Bool {
return FBSDKApplicationDelegate.sharedInstance()。application(
application,$ b $ openURL:url,
sourceApplication:sourceApplication,
annotation:annotation)
}

func applicationWillResignActive(application:UIApplication){
//当应用程序即将从活动状态转移到非活动状态时发送。对于某些类型的临时中断(例如来电或SMS消息)或用户退出应用程序并开始转换到后台状态时,可能会发生这种情况。
//使用此方法可暂停正在进行的任务,禁用定时器,并降低OpenGL ES帧速率。游戏应该使用这种方法来暂停游戏。

$ b $ func applicationDidEnterBackground(application:UIApplication){
//使用此方法释放共享资源,保存用户数据,使计时器无效并存储足够的应用程序状态信息你的应用程序到当前的状态,以防以后终止。
//如果您的应用程序支持后台执行,则调用此方法而不是applicationWillTerminate:当用户退出时。
}

func applicationWillEnterForeground(application:UIApplication){
//被称为从后台到非活动状态转换的一部分;在这里你可以撤消进入背景的许多变化。
}

func applicationDidBecomeActive(application:UIApplication){
//在应用程序处于非活动状态时,重新启动暂停(或尚未启动)的任务。如果应用程序以前位于后台,则可以选择刷新用户界面。

FBSDKAppEvents.activateApp()
}

func applicationWillTerminate(application:UIApplication){
//当应用程序即将终止时调用。保存数据,如果适用。另请参阅applicationDidEnterBackground :.

$ b func application(application:UIApplication,didReceiveRemoteNotification userInfo:[NSObject:AnyObject],
fetchCompletionHandler completionHandler:(UIBackgroundFetchResult) - > Void){
/ /如果在应用程序处于后台时收到通知消息,
//直到用户点击启动应用程序的通知,才会触发此回调。
// TODO:处理通知数据

//打印消息ID。
print(Message ID:\(userInfo [gcm.message_id]!))

//打印完整的信息。
print(%@,userInfo)
}

帮帮我! :-)谢谢

编辑
经过更多的调试,我的控制台现在正在打印这个错误:
警告:应用程序委托接收到的应用程序的调用:didReceiveRemoteNotification:fetchCompletionHandler:但完成处理程序从未被调用。

在您上次编辑时,您正在收到通知。否则,它不会给你警告,说完成处理程序从来没有被调用过。



你可以通过调用去除警告(并使iOS快乐)完成处理程序。例如,

completionHandler(.NoData)



这是告诉iOS,没有新的数据与您的应用程序需要下载的通知关联。


I'm trying to send remote notifications from my Firebase console through the cloud messaging but my phone isn't receiving any of the alerts. I have already uploaded my certificates to Firebase and I'm using the default code given by the Firebase tutorial to receive notifications.

Here is a picture of my certificates showing that I have already created it

Here is my code in which I implemented it as well. class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

override init() {
    FIRApp.configure()
    FIRDatabase.database().persistenceEnabled = true
}

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    let notificationTypes : UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
    let notificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)
    application.registerForRemoteNotifications()
    application.registerUserNotificationSettings(notificationSettings)

    return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}

func application(application: UIApplication,
    openURL url: NSURL,
    sourceApplication: String?,
    annotation: AnyObject) -> Bool {
        return FBSDKApplicationDelegate.sharedInstance().application(
            application,
            openURL: url,
            sourceApplication: sourceApplication,
            annotation: annotation)
}

func applicationWillResignActive(application: UIApplication) {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

    FBSDKAppEvents.activateApp()
}

func applicationWillTerminate(application: UIApplication) {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

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)
}

Would appreciate any help! :-) Thank you

EDIT Upon more debugging, my console is now printing this error: Warning: Application delegate received call to -application:didReceiveRemoteNotification:fetchCompletionHandler: but the completion handler was never called.

解决方案

It seems like, based on your last edit, you are receiving the notification. Otherwise, it wouldn't be giving you that warning that the completion handler was never called.

You can go ahead and remove the warning (and make iOS happy) by calling the completion handler. For example,

completionHandler(.NoData)

which is telling iOS that there was no new data associated with the notification that your app needed to download.

这篇关于Firebase远程通知不能接收?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆