簡體   English   中英

Xamarin.Forms - iOS RegisteredForRemoteNotifications 沒有被調用

[英]Xamarin.Forms - iOS RegisteredForRemoteNotifications not getting called

I am trying to register a physical iOS (13) device for remote notifications using Xamarin.iOS in a Xamarin.Forms project.

在它完美運行大約兩周后,我遇到了調用UIApplication.SharedApplication.RegisterForRemoteNotifications()后的問題(請參閱下面的完整代碼)

AppDelegate 的RegisteredForRemoteNotificationsFailedToRegisterForRemoteNotifications都沒有被調用。

唯一改變的是我在我的 app-id 中添加了一個生產 APNS-Certificate,現在看起來像這樣: App id redacted with xxxx

我可以 select Xcode 中的相關開發供應配置文件,我可以毫無錯誤地部署應用程序。

AppDelgate 中的相關代碼:

完成發射:

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        Forms.SetFlags("IndicatorView_Experimental", "SwipeView_Experimental");

        Forms.Init();
        //other init methods omitted
        LoadApplication(new App());

        var baseFinished = base.FinishedLaunching(app, options);

        RegisterForRemoteNotifications();

        return baseFinished;
    }

注冊遠程通知:

public void RegisterForRemoteNotifications()
    {
        if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
        {
            var options = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Sound |
                          UNAuthorizationOptions.Sound;

            UNUserNotificationCenter.Current.RequestAuthorization(options,(granted, error) =>
                {
                    if (granted)
                    {
                        //this method is getting called
                        InvokeOnMainThread(UIApplication.SharedApplication.RegisterForRemoteNotifications);
                    }
                });
        }
        //checking for other iOS versions omitted
    }

RegisteredForRemoteNotifications 和 FailedToRegisterForRemoteNotifications - 兩者都沒有被調用:

public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)

    {
        var bytes = deviceToken.ToArray();
        var token = BitConverter.ToString(bytes).Replace("-", "");
        Debug.WriteLine($"Got iOS notification token: {token}");

        DependencyService.Get<INotificationRegistrationService>().OnTokenAcquired(token, DeviceType.Apple);
    }

public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
    {
        Debug.WriteLine("error on register remote notifications ");
    }

我可能只是在代碼或證書中犯了一個錯誤。

對於有同樣問題的任何人,請嘗試使用移動熱點/移動互聯網注冊 iPhone。 這就是為我解決的問題

我猜我的防火牆以某種方式阻止了與 apns 服務器的通信。 我不知道為什么,因為它以前有效。

現在我將調查通信究竟是如何被阻止的,如果我有任何相關信息,我會在這里發布。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM