Код: Выделить всё
class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate {
let gcmMessageIDKey = "gcm.message_id"
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
FirebaseApp.configure()
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in
}
application.registerForRemoteNotifications()
Messaging.messaging().delegate = self
return true
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if let messageID = userInfo[gcmMessageIDKey] {
print("Message ID: \(messageID)")
}
guard let aps = userInfo["aps"] as? [String: AnyObject] else {
completionHandler(.failed)
return
}
print("got something, aka the \(aps)")
print("11111111")
print(userInfo)
completionHandler(UIBackgroundFetchResult.newData)
}
// Receive displayed notifications for iOS 10 devices.
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
// THIS ONE IS ONLY CALLED WHEN APP IS RUNNING
print("2222222222")
print(userInfo)
//completionHandler([[.banner, .badge, .sound]])
completionHandler([[.banner, .badge]])
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
// THIS ONE IS ONLY CALLED WHEN YOU TAP ON THE RECEIVED MESSAGE
let userInfo = response.notification.request.content.userInfo
print("333333333333")
print(userInfo)
completionHandler()
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("Unable to register for remote notifications: \(error.localizedDescription)")
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
}
}
< /code>
Что я заметил до сих пор: < /p>
willPresent
Код: Выделить всё
didReceive
Мой 1 -й вопрос:
Почему DidReceivereMotenotification никогда не вызывается? >
Как именно он будет вести себя, как WillPresent или DidReceive или другим образом? И Dodreceive все еще работает так же в сборке релиза? Если да, то могу ли я просто удалить didReceiveremotenotification или это все еще нужно?>
Подробнее здесь: https://stackoverflow.com/questions/794 ... emotenotif