0

I am trying to make a flutter app that uses APNS for iOS push notifications and I do not want to use firebase, as I am using AWS SNS in the backend to deliver the push notifications via APNS. I have the application Identifier set up and Keys generated from the apple developer portal. How can I get the APNS device token, I am stuck at this point, tried multiple things but none worked? Below is my AppDelegate.swfit code

    import UIKit
    import Flutter

    @UIApplicationMain
    @objc class AppDelegate: FlutterAppDelegate {
      override func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
      ) -> Bool {


        GeneratedPluginRegistrant.register(with: self)

        UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate
        UIApplication.shared.registerForRemoteNotifications()
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
      }

      func application(_ application: UIApplication,
                didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) 
      {
        let hexString = map { deviceToken(format: "%02.2hhx", $0)}.joined()
        print(hexString)
        
                      
      }
    }
Kalindu
  • 111
  • 2
  • 9

1 Answers1

0

with the AWS Amplify libraries for Flutter you can easy receive a device token.

void myTokenReceivedHandler(String token) {
  // Do something with the received token
}

final subscription = Amplify.Notifications.Push.onTokenReceived
  .listen(myTokenReceivedHandler);

// Remember to cancel the subscription when it is no longer needed
subscription.cancel();

here detailed description

dstreissi
  • 209
  • 3
  • 14