简体   繁体   English

Xamarin Firebase iOS 11未生成FCM令牌

[英]Xamarin Firebase iOS 11 No FCM Token Generated

My app registers with firebase for push notifications, receives a token, and then provides that token as a querystring parameter of the url loaded by a webview. 我的应用向firebase注册以进行推送通知,接收令牌,然后将该令牌作为Webview加载的URL的querystring参数提供。

Although the code executes and no failures are reported, the token is always null in iOS 11. 尽管代码已执行且未报告任何错误,但在iOS 11中令牌始终为null。

The below code works on iOS v9.x on either remote simulator or installed on a device, but does not work in either environment when iOS v11.x. 以下代码可在远程模拟器上或安装在设备上的iOS v9.x上运行,但在iOS v11.x上的任何环境下均无法运行。

Has anyone experienced this? 有人经历过吗? Anyone have helpful suggestions? 有人有帮助的建议吗? Thank you in advance for your assistance, I'm pulling out what's left of my hair over here. 预先感谢您的帮助,我在这里拉出我剩下的头发。

I am using the following packages/versions: 我正在使用以下软件包/版本:

  • Xamarin.Firebase.iOS.CloudMessaging v2.0.4.1 Xamarin.Firebase.iOS.CloudMessaging v2.0.4.1
  • Xamarin.Firebase.iOS.Core v4.0.13 Xamarin.Firebase.iOS.Core v4.0.13
  • Xamarin.Firebase.iOS.InstanceId v2.0.8 Xamarin.Firebase.iOS.InstanceId v2.0.8

From AppDelegate.cs: 从AppDelegate.cs:

    public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
    {
        // Override point for customization after application launch.
        // If not required for your application you can safely delete this method

        // Register your app for remote notifications.
        if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
        {
            // iOS 10 or later
            var authOptions = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound;
            UNUserNotificationCenter.Current.RequestAuthorization(authOptions, (granted, error) =>
            {
                System.Console.WriteLine(granted);
            });

            // For iOS 10 display notification (sent via APNS)
            UNUserNotificationCenter.Current.Delegate = this;

            // For iOS 10 data message (sent via FCM)
            Messaging.SharedInstance.Delegate = this;
        }
        else
        {
            // iOS 9 or before
            var allNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound;
            var settings = UIUserNotificationSettings.GetSettingsForTypes(allNotificationTypes, null);
            UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
        }

        UIApplication.SharedApplication.RegisterForRemoteNotifications();

        //configure firebase analytics.
        App.Configure();

        DoFCMConnect();
        return true;
    }

    private void DoFCMConnect()
    {
        Messaging.SharedInstance.ShouldEstablishDirectChannel = true;

        Console.WriteLine("Connected to FCM");

        //removed when updated to newest firebase version
        //Messaging.SharedInstance.Connect(error => {
        //    if (error != null)
        //    {
        //        System.Console.WriteLine(String.Format("Re-Connection to FCM Failed: {0}", error.ToString()));
        //    }
        //    else
        //    {
        //        System.Console.WriteLine("Re-Connected to FCM.");
        //    }
        //});
    }

From WebViewController.cs: 从WebViewController.cs:

public override void ViewDidLoad()
    {
        string url = "https://www.mydomainname.com"; // NOTE: https secure request is required.

        string token = InstanceId.SharedInstance.Token;
        string fcm = Messaging.SharedInstance.FcmToken;

        if (token == null && fcm != null)
        {
            token = fcm;
        }

        if (String.IsNullOrEmpty(token))
        {
            url += "/login";
        }
        else
        {
            url += "/app-in/{0}"; //page accepts token and associates it to the user after login.
            url = String.Format(url, System.Web.HttpUtility.UrlEncode(token));
        }

        WebView.LoadRequest(new NSUrlRequest(new NSUrl(url)));

    }

Both string token and string fcm contain a value for iOS 9, however both are null in iOS 11. 字符串令牌和字符串fcm都包含iOS 9的值,但是在iOS 11中均为null。

It is a known issue , refer to here . 这是一个已知问题,请参阅此处

Try the steps provided by rsattar. 尝试rsattar提供的步骤。

  • downgrade FirebaseInstanceID to 2.0.0 FirebaseInstanceID降级到2.0.0

  • place UIApplication.shared.registerForRemoteNotifications() at first line in FinishedLaunching . UIApplication.shared.registerForRemoteNotifications()放在FinishedLaunching第一行。

  • uninstall/reinstall your app. 卸载/重新安装您的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 适用于iOS的Xamarin Firebase出现fcm 501错误 - Xamarin Firebase for iOS giving fcm 501 error Ionic Push FCM iOS - 获取设备令牌(不是 firebase 令牌) - Ionic Push FCM iOS - get device token (not firebase token) 如何在 iOS Swift 中使用 Firebase FCM 令牌在 PubNub 上注册推送通知 - How to register push notification on PubNub with Firebase FCM token in iOS Swift 对于长度为 163 的 FCM 令牌,Firebase 通知未到达 iOS - Firebase notification not arriving on iOS for FCM token with length 163 如何使用Firebase检索FCM令牌? - Ways to retrieve FCM Token with Firebase? iOS上的Firebase推送通知:FCM说令牌错误:未注册,但应用程序未刷新令牌 - Firebase Push Notifications on iOS: FCM says token error: not registered but app gets no refreshed token Firebase 在检索发件人 ID 的 FCM 令牌之前未设置 APNS 设备令牌 - Flutter iOS - Firebase APNS device token not set before retrieving FCM Token for Sender ID - Flutter iOS Firebase:如何将设备令牌转换为FCM令牌 - Firebase: How to translate a device token into a FCM token Xamarin.iOS Firebase 未收到推送通知但收到令牌 - Xamarin.iOS Firebase not receiving push notifications but receiving token 内部监督办公室10上的Firebase FCM澄清 - Firebase FCM on IOS 10 clarification
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM