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