Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin Firebase iOS 11未生成FCM令牌_Ios_Firebase_Xamarin_Xamarin.ios - Fatal编程技术网

Xamarin Firebase iOS 11未生成FCM令牌

Xamarin Firebase iOS 11未生成FCM令牌,ios,firebase,xamarin,xamarin.ios,Ios,Firebase,Xamarin,Xamarin.ios,我的应用程序向firebase注册推送通知,接收令牌,然后将该令牌作为webview加载的url的查询字符串参数提供 尽管代码执行且未报告任何故障,但在iOS 11中令牌始终为空 下面的代码在远程模拟器或安装在设备上的iOS v9.x上工作,但在iOS v11.x运行时,这两种环境都不工作 有人经历过吗?有人有有用的建议吗?提前谢谢你的帮助,我正在把我剩下的头发拔出来 我正在使用以下软件包/版本: Xamarin.Firebase.iOS.CloudMessaging v2.0.4.1 Xama

我的应用程序向firebase注册推送通知,接收令牌,然后将该令牌作为webview加载的url的查询字符串参数提供

尽管代码执行且未报告任何故障,但在iOS 11中令牌始终为空

下面的代码在远程模拟器或安装在设备上的iOS v9.x上工作,但在iOS v11.x运行时,这两种环境都不工作

有人经历过吗?有人有有用的建议吗?提前谢谢你的帮助,我正在把我剩下的头发拔出来

我正在使用以下软件包/版本:

Xamarin.Firebase.iOS.CloudMessaging v2.0.4.1 Xamarin.Firebase.iOS.Core v4.0.13 Xamarin.Firebase.iOS.InstanceId v2.0.8 从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.");
        //    }
        //});
    }
从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)));

    }

字符串标记和字符串fcm都包含iOS 9的值,但在iOS 11中都为空。

这是一个已知问题,请参阅

请尝试rsattar提供的步骤

将FirebaseInstanceID降级为2.0.0

将UIApplication.shared.RegisterForRemotonifications放在FinishedLaunching的第一行

卸载/重新安装你的应用程序


谢谢你的回复,这确实帮了大忙。我之前曾尝试按照其他帖子的建议进行降级,但失败的是:通过NuGet删除所有Firebase.iOS软件包,然后重新安装依赖性最低的.CloudMessaging 2.0。希望这个小道消息能帮助别人。再次感谢你的回复,科尔。