'didRegisterForRemoteNotificationsWithDeviceToken' никогда не вызывалсяIOS

Программируем под IOS
Ответить
Anonymous
 'didRegisterForRemoteNotificationsWithDeviceToken' никогда не вызывался

Сообщение Anonymous »

Мне нужна помощь.
Я совершенно не понимаю, почему мои уведомления не работают.
Мой 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.
}
}
Проблема в том, что функция «didRegisterForRemoteNotificationsWithDeviceToken» никогда не вызывается.
Я также создал «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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»