gpt4 book ai didi

ios - Onesignal NotificationOpened 在 iOS 应用程序中不起作用

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

我尝试在我的 ios 应用程序中使用 Onesignal Notifications,它是在 Visual Studio 中使用 Xamarin 创建的。我想让应用程序在用户点击通知时打开 ViewController,但它不起作用。当用户点击通知时,应用程序打开 ViewController,当用户应用程序转到后台时,该 View Controller 处于事件状态。希望有人指出,我在哪里犯了错误这里的代码:

public class AppDelegate : UIApplicationDelegate
{
public static UIStoryboard Storyboard = UIStoryboard.FromName("Main", null);
public override UIWindow Window {
get;
set;
}

public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{
OneSignal.Current.StartInit("mykey")
.InFocusDisplaying(OSInFocusDisplayOption.None)
.HandleNotificationOpened(HandleNotificationOpened)
.EndInit();
OneSignal.Current.IdsAvailable(IdsAvailable);
return true;
}
void IdsAvailable(string userID, string pushToken)
{
GlobalUserInfo._token = userID;
}
private static void HandleNotificationOpened(OSNotificationOpenedResult result)
{
OSNotificationPayload payload = result.notification.payload;
Dictionary<string, object> additionalData = payload.additionalData;

if (additionalData != null)
{
UINavigationController NavigationController = (UINavigationController)Storyboard.InstantiateInitialViewController();
NotificationsViewController notificationsController = Storyboard.InstantiateViewController("NotificationsViewController") as NotificationsViewController;
NavigationController.PushViewController(notificationsController, true);
}
}
}

NotificationsViewController 是用户收到的所有通知的简单列表。

已更新正如我所注意到的,函数 HandleNotificationOpened 在 iOS 中不起作用。

已更新发现错误。我忘了,我在其他地方使用 OneSignal Init。当我删除重复项时,HandleNotificationOpened 开始正常工作。

最佳答案

您应该找到当前的根 ViewController,而不是创建一个新实例。所以请这样修改:

if (additionalData != null)
{
UINavigationController NavigationController = (UINavigationController)Window.RootViewController;
NotificationsViewController notificationsController = Storyboard.InstantiateViewController("NotificationsViewController") as NotificationsViewController;
NavigationController.PushViewController(notificationsController, true);
}

此外,如果根 ViewController 是 UITabBarController,请提供此 View Controller (NotificationsViewController)。

关于ios - Onesignal NotificationOpened 在 iOS 应用程序中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48227979/

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