SwiftUI 2, UIApplicationDelegateAdaptor not working properly

Hi all,
I'm using SwiftUI 2 and I need to receive a callback in my app:
Code Block
didRegisterForRemoteNotificationsWithDeviceToken

I'm putting this in my @main App struct:
Code Block
@UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate


The problem is that only willFinishLaunchingWithOptions and didFinishLaunchingWithOptions get called. The rest just don't get called at all. I'm fine with the other as there are modifiers to replace, but there is nothing for the APN token callback.

I'm stuck here.
Any help is much appreciated. Thanks
Post not yet marked as solved Up vote post of Son Seo Down vote post of Son Seo
2.7k views

Replies

Hi
I have error when I add this line

Unknown attribute 'UIApplicationDelegateAdaptor'

I have experienced the same behavior. No remote notification registration methods are called.

I don't get any call.

I created a separat post for that https://developer.apple.com/forums/thread/681306

Just ran into this as well running XCode 13.4.1, testing with device running iOS 15.5. The problem turned out to be swizzling of the AppDelegate methods (by multiple libraries). If you're running into this, do a search for didRegisterForRemoteNotificationsWithDeviceToken across your dependencies and look for any places where swizzling is taking place.