[英]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: 我正在使用以下软件包/版本:
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.