0

I am using Firebase for Push Notification in my Flutter App. I didn't receive any APNS token from iOS. Whether the IOS simulator provides an APNS token or not or if it requires a Physical Device. AppDelegate.swift code.

import UIKit
import Flutter
import UserNotifications
import Firebase

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    if #available(iOS 10.0, *) {
           let center  = UNUserNotificationCenter.current()

           center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
               if error == nil{
                DispatchQueue.main.async {
                  UIApplication.shared.registerForRemoteNotifications()
                }
               }
           }

       }
       else {
           UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil))
           UIApplication.shared.registerForRemoteNotifications()
       }
    FirebaseApp.configure()
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

enter image description here

Wasiq Hussain
  • 49
  • 1
  • 7

3 Answers3

1

You need to test registering remote notification on real device, if you run on simulator ou will get this error: "[0] (null) "NSLocalizedDescription" : "remote notifications are not supported in the simulator".

Mr.SwiftOak
  • 1,469
  • 3
  • 8
  • 19
0

I can confirm what Mr.SwiftOak said, you can use the getAPNSToken function only on a real iOS device, otherwise it will return null on simulators.

George Dobrin
  • 41
  • 1
  • 1
0

you must need to run in device . because simulator not provide the token it will retunrn null value.

  • This has already been mentioned in the other answers. – Eric Aya Feb 28 '22 at 10:54
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31177387) – tomerpacific Mar 04 '22 at 10:00