Я совершенно не понимаю, почему мои уведомления не работают.
Мой AppDelegate выглядит так: п>
Код: Выделить всё
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()
print("token: \(token)")
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("failed to register for remote notifications with with error: \(error)")
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in
print("granted: (\(granted)")
}
UIApplication.shared.registerForRemoteNotifications()
return true
}
// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
}
Я также создал «SSL-сертификаты службы push-уведомлений Apple» в своей учетной записи разработчика, добавил «Push-уведомления» в мои возможности в Xcode, но он все еще не работает. Каждый раз, когда я нажимаю «Разрешить», чтобы разрешить уведомления, он говорит «Доступ предоставлен», но не распечатывает какой-либо токен устройства. «isRegisterForRemoteNotifications» также возвращает true.
Я также искал в Интернете около 2–3 часов, но пока не нашел решения.
Я использую Xcode 12 Beta 2 и iOS 14 Dev Beta 2.
Спасибо.
Подробнее здесь: https://stackoverflow.com/questions/628 ... ver-called
Мобильная версия