gpt4 book ai didi

ios - FinishedLaunching 中的 LaunchOption 始终为 null (Xamarin.iOS)

转载 作者:行者123 更新时间:2023-11-29 00:58:11 26 4
gpt4 key购买 nike

我正在为我的 iOS 应用程序实现远程通知,并且我正在尝试在应用程序未运行时捕获通知负载。问题是,当调用 FinishedLaunching 时,launchOption 参数始终为 null。在其他情况下,当应用程序处于后台或处于事件状态时,通知效果很好。我不明白为什么,根据引用资料和博客文章,它应该有效。这是我正在使用的代码:

    public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{
//new UIAlertView("launchOption", launchOptions != null ? "Yes" : "No", null, "").Show();
if(launchOptions != null && launchOptions.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey))
{
//new UIAlertView("launchOption", "launchOption != null", null, "");
this.viewModel.Loading(false);

NSObject result;
if (launchOptions.TryGetValue (UIApplication.LaunchOptionsRemoteNotificationKey, out result)){
NSNotification notification = result as NSNotification;
DispatchPushNotification(application, notification.UserInfo);
Console.WriteLine ("Got a local notification: {0}", notification);
}
...

我做错了什么?

最佳答案

我决定更改检索负载的代码。我注意到每次我使用 options.TryGetValue(...) 时,启动选项中的输入值为 null。删除此行并使用以下内容确实解决了我的问题。

if (launchOptions != null && launchOptions.ContainsKey (UIApplication.LaunchOptionsRemoteNotificationKey)) { 
Console.WriteLine ("launchOption != null and LaunchOptionsRemoteNotificationKey present");
NSDictionary notification = launchOptions.ObjectForKey(UIApplication.LaunchOptionsRemoteNotificationKey) as NSDictionary;
if (notification != null)
// do something
}
}

不知道是不是bug,没有太多时间测试。

关于ios - FinishedLaunching 中的 LaunchOption 始终为 null (Xamarin.iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37385912/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com