1
昨天我更新我的应用程序的2至3迅速iOS上的10推挽没有收到当应用程序在前台
func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) {
UIApplication.shared.registerForRemoteNotifications()
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print(error.localizedDescription)
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
// Save Installation if registered successfully
}
//MARK: Recieved Notification
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
print("received a notification")
}
这样的背景推送通知工作正常,在两个应用程序,但在我的应用程序之一,其不接收前景是任何推,didReceiveRemoteNotification是从来没有得到所谓的
事情我已经检查,推动在能力
使用此代码启用的通知,为推动notific注册在这两个应用
UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.badge, .alert, .sound], categories: nil))
不仅如此ations,我已经试过UNUserNotificationCenterDelegate为iOS 10,但仍然没有它的代表功能调用。
这只适用于iOS 10手机,iOS 8和9就像魅力一样。 所以,我真的不知道为什么它只有我2 SWIFT 3 IOS 10应用程序之一,从来没有打电话didReceiveRemoteNotification当应用程序打开时
这是我尝试
//Added in didFinishLaunchingWithOptions
if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.current()
center.delegate = self
center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
if error == nil{
UIApplication.shared.registerForRemoteNotifications()
}
}
}
//Delegates
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping() -> Void) {
print("push2")
}
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
print("push1")
}
'UIApplication.shared.registerUserNotificationSettings'但是,这不是你怎么做iOS中10.你使用Ť他请UNUserNotificationCenter注册。你的'application:didReceiveRemoteNotification'等等完全不相关。你需要重写_completely_。观看相关的WWDC 2016视频(其中有两个)。 – matt
@matt,因为我在问题中写道,我已经尝试过UNUserNotificationCenter的代理和新的注册代码,但它仍然没有工作,我试过这个http://stackoverflow.com/questions/39382852/didreceiveremotenotification-not-called -ios-10以及旧的代码也适用于我的其他应用程序多数民众赞成我的问题说 – user528432
如果您正在编译对iOS 10您必须切换到UNUserNotificationCenter。因此,您有两种选择:切换或不针对iOS 10进行编译。您没有显示任何UNUserNotificationCenter代码,因此我没有理由相信您做得对。 – matt