gpt4 book ai didi

ios - 为什么设备在后台收不到推送通知?

转载 作者:行者123 更新时间:2023-11-28 15:59:57 34 4
gpt4 key购买 nike

在 iOS10 上,当应用程序打开时我收到推送通知,但是当我按下主页按钮并且应用程序处于后台模式时 - 它没有收到任何信息。

我的代码是:

class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, FIRMessagingDelegate {

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
if #available(iOS 10.0, *) {
let authOptions: UNAuthorizationOptions = [.Alert, .Badge, .Sound]
UNUserNotificationCenter.currentNotificationCenter().requestAuthorizationWithOptions([.Sound, .Alert, .Badge], completionHandler: { (granted: Bool, error: NSError?) 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)
}

// Connect to FCM since connection may have failed when attempted before having a token.
connectToFcm()

application.registerForRemoteNotifications()

}
}

@available(iOS 10.0, *)
func userNotificationCenter(center: UNUserNotificationCenter, willPresentNotification notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo

}

@available(iOS 10.0, *)
func userNotificationCenter(center: UNUserNotificationCenter, didReceiveNotificationResponse response: UNNotificationResponse, withCompletionHandler completionHandler: () -> Void) {
//Handle the notification
print("User Info => ",response.notification.request.content.userInfo)
completionHandler()
}

所以我找不到问题出在哪里?任何想法?还是iOS10有什么新东西?

我已经开启了这些功能:

enter image description here enter image description here

最佳答案

你试过这样做吗

enter image description here 还有这个

enter image description here

完成这些后请确认,我将相应地编辑此答案

关于ios - 为什么设备在后台收不到推送通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41222134/

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