2

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

这是我的证书的图片,表明我已经创建了它 图片

这是我在其中实现它的代码。类 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 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 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)
}

编辑 经过更多调试,我的控制台现在正在打印此错误:

警告:应用程序委托收到了对 -application:didReceiveRemoteNotification:fetchCompletionHandler: 的调用,但从未调用过完成处理程序。

4

1 回答 1

1

根据您上次的编辑,您似乎正在收到通知。否则,它不会向您发出从未调用完成处理程序的警告。

您可以通过调用完成处理程序继续删除警告(并使 iOS 开心)。例如,

completionHandler(.NoData)

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

于 2016-06-20T22:21:06.867 回答