Swiftui iOS - Ошибка уведомлений об уведомлениях Firebase Push: токен устройства APNS не установлен перед тем, как получIOS

Программируем под IOS
Ответить Пред. темаСлед. тема
Anonymous
 Swiftui iOS - Ошибка уведомлений об уведомлениях Firebase Push: токен устройства APNS не установлен перед тем, как получ

Сообщение Anonymous »

До года или что -то в этом роде работали уведомления, и я перестал обращать на них внимание, поэтому я не знаю, получаю ли я ошибку, поскольку обновление Swift/swiftui/xcode/ios или что -то еще. Это ошибка: < /p>

Код: Выделить всё

APNS device token not set before retrieving FCM Token for Sender ID 'xxxxxxxxxxx'.Be sure to re-retrieve the FCM token once the APNS device token is set.
Что я пробовал:
на основе всех видов ответов для того же вопроса.
[*] отменил токен APN и замену старого в настройках проекта Firebase < /p>
< /li>

Обновление до последней Firebase SDK

Следуя различным учебным пособиям по этой реализации, включая попытку различных классов AppDelegate из этих
< /li>
Настройка FireBaseAppDelegateProxyenabled < /code> к false < /p>
< /li>
< /ul>
Согласно комментарию здесь: https://github.com/firebase/firebase-io ... sues/12445 Причина-плохое время, в котором вызываются функции, но я не совсем понимаю, что не понимаю именно он имеет в виду. Код обрезал, который он предоставляет, - это то, что я использую в любое время за много секунд после запуска приложения, и токен - это Nil
Это последнее приложение, которое я 'm Попробую: < /p>

Код: Выделить всё

class AppDelegate: NSObject, UIApplicationDelegate {

let gcmMessageIDKey = "gcm.message_id"

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {

FirebaseApp.configure()

Messaging.messaging().delegate = self

UNUserNotificationCenter.current()
.requestAuthorization(
options: [.alert, .sound, .badge]) { granted, _ in
print("Permission granted: \(granted)")
guard granted else { return }
UNUserNotificationCenter.current().getNotificationSettings { settings in
print("Notification settings: \(settings)")
guard settings.authorizationStatus == .authorized else { return }
DispatchQueue.main.async {
application.registerForRemoteNotifications()
}
}
}

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 full message.
print(userInfo)

completionHandler(UIBackgroundFetchResult.newData)
}

func application(_ application: UIApplication,
didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("Unable to register for remote notifications: \(error.localizedDescription)")
}

func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
print("device token")
let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
let token = tokenParts.joined()
print("Device Token: \(token)")
}

}

extension AppDelegate: UNUserNotificationCenterDelegate {
// 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

// With swizzling disabled you must let Messaging know about the message, for Analytics
// Messaging.messaging().appDidReceiveMessage(userInfo)

// ...

// Print full message.
print(userInfo)

// Change this to your preferred presentation option
completionHandler([[.banner, .badge, .sound]])
}

func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo

print(userInfo)

completionHandler()
}
}

extension AppDelegate: MessagingDelegate {
// [START refresh_token]
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
print("Firebase registration token: \(String(describing: fcmToken))")

let dataDict: [String: String] = ["token": fcmToken ?? ""]
NotificationCenter.default.post(
name: Notification.Name("FCMToken"),
object: nil,
userInfo: dataDict
)

}

}
Надеюсь, у кого -то есть идея, что случилось.

Подробнее здесь: https://stackoverflow.com/questions/794 ... -set-befor
Реклама
Ответить Пред. темаСлед. тема

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

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

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

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

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

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