我正在使用 ios/xamarin 构建移动应用程序,我想确定当应用程序在后台运行或未处于事件状态时用户单击 ios/xamarin 中通知中心的通知时将触发哪些事件。
我检查了当我点击通知中心的通知时触发了 ReceivedRemoteNotification
事件,无论应用是否处于事件状态。
最佳答案
当应用程序处于事件状态时:
如果您的应用程序处于事件状态,则默认情况下将调用以下方法来接收通知:
DidReceiveRemoteNotification
如果您想默认调用 ReceivedRemoteNotification,那么您必须添加值为 remote-notification的键 UIBackgroundModes strong> 在 info.plist 文件中
当应用程序在后台时
iOS 会自行显示收到的通知。目前在这种情况下无法调用任何方法。因此,当用户再次点击收到的通知时,将调用 DidReceiveRemoteNotification 方法,您将在其中收到有关详细信息的通知。
当应用程序处于 InActive 状态时:
iOS 会自行显示收到的通知,在这种情况下也无法调用任何方法。现在,当用户点击收到的通知时,将调用 FinishedLaunching 方法并使用以下代码,您可以获得本地和远程通知的数据:
if (options != null)
{
// check for a local notification
if (options.ContainsKey(UIApplication.LaunchOptionsLocalNotificationKey))
{
UILocalNotification localNotification = options[UIApplication.LaunchOptionsLocalNotificationKey] as UILocalNotification;
if (localNotification != null)
{
//--your code
}
}
// check for a remote notification
if (options.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey))
{
NSDictionary remoteNotification = options[UIApplication.LaunchOptionsRemoteNotificationKey] as NSDictionary;
if (remoteNotification != null)
{
//--your code
}
}
}
关于c# - 当用户点击 ios/xamarin 通知中心的通知时触发什么事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28264033/