1

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)
        
                      
      }
    }

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your reply, but can I just retrieve the device token without using AWS amplify?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.