gpt4 book ai didi

ios - 如何使用 Google Cloud Messaging 在 iOS 中处理后台通知

转载 作者:行者123 更新时间:2023-11-30 13:18:46 25 4
gpt4 key购买 nike

我在我的 iOS 应用中实现了用于推送通知的 Google Cloud Messaging。而且效果很好。

但是,在我的应用程序中,用户可以登录和注销。所以我需要确保用户在注销时不会收到通知。

我可以在应用程序运行时检查用户是否在我的应用程序委托(delegate)中登录。以下是我在 AppDelegate.swift 中执行此操作的方法:

func application( application: UIApplication,didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
GCMService.sharedInstance().appDidReceiveMessage(userInfo);

if defaults.stringForKey("authKey") != nil{
NSNotificationCenter.defaultCenter().postNotificationName(messageKey, object: nil, userInfo: userInfo)
showNotification(userInfo)
}
}

但是,当应用程序未运行时,我在应用程序委托(delegate)中检查用户是否登录的方法不起作用。而且我不知道在应用程序未运行时在哪里进行此检查。当应用程序在后台时,使用哪些方法来显示通知?

Here is all of my AppDelegate

最佳答案

您需要处理应用程序委托(delegate)

application:didReceiveRemoteNotification:fetchCompletionHandler:

查看与remote notification in background mode相关的详细博客

关于ios - 如何使用 Google Cloud Messaging 在 iOS 中处理后台通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37966391/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com