RegisterForRemoteNotifications 重写方法未被调用

RegisterForRemoteNotifications override method not being called

我在 AppDelegate 中为虚拟 RegisterForRemoteNotifications 创建了覆盖,如下所示:

public async override void RegisteredForRemoteNotifications(NSApplication application, NSData deviceToken)
        {
            Debug.WriteLine("This method has been reached");
            base.RegisteredForRemoteNotifications(application, deviceToken);

            var credentials = NotificationRegistrar.Credentials;
            var client = new AmazonSimpleNotificationServiceClient(credentials, RegionEndpoint.APSoutheast2);
            var request = new CreatePlatformEndpointRequest();
            request.PlatformApplicationArn = "{ARN}";
            request.Token = deviceToken.Description;

            await client.CreatePlatformEndpointAsync(request);
        }

但是,我的方法根本没有到达,无论它可能(应该)从哪里触发。起初,我认为这可能是因为我在应用程序初始化后从 AppDelegate 外部调用了 RegisterForRemoteNotifications 方法。但是当将调用移动到 DidFinishLaunching 内部时,无论是在 Forms.Init 之前还是之后,或者无论我尝试了什么,都没有达到我的覆盖。

现在有趣的是,也没有调用 FailedToRegisterForRemoteNotifications 覆盖。但是,如果我取消选中项目 Mac 签名部分下的“签署应用程序包”,则会调用 FailedToRegisterForRemoteNotifications,这可能是因为需要配置文件APN 注册。但是,为什么在启用身份和配置的情况下签名都不会被调用?所需的所有权限/功能都在那里(我假设)。 com.apple.developer.aps-environment 已在 Entitlements 中设置为 development

同样有趣的是,每当我调用 Register/UnregisterForRemoteNotifications 时,IsRegisteredForRemoteNotifications 确实会发生变化,但不会调用覆盖.

看来 Big Sur 本身就是开发环境的问题,因为它在生产环境中工作。解决方案是恢复到 Catalina 或更低版本,或者尝试使用生产版本测试通知。