c# - 当用户点击 ios/xamarin 通知中心的通知时触发什么事件

标签 c# ios xamarin apple-push-notifications

我正在使用 ios/xamarin 构建移动应用程序,我想确定当应用程序在后台运行或未处于事件状态时用户单击 ios/xamarin 中通知中心的通知时将触发哪些事件。

我检查了当我点击通知中心的通知时触发了 ReceivedRemoteNotification 事件,无论应用是否处于事件状态。

最佳答案

当应用程序处于事件状态时:

如果您的应用程序处于事件状态,则默认情况下将调用以下方法来接收通知:

DidReceiveRemoteNotification

如果您想默认调用 ReceivedRemoteNotification,那么您必须添加值为 remote-notificationUIBackgroundModes 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/

相关文章:

c# - ASP.NET 中用户 IP 地址的防弹检测

c# - 添加更多选项卡时如何缩小 tabItem 大小(例如 google chrome 选项卡)

ios - 使用羽化边缘裁剪图像

ios - View 堆栈、UIViewController 和旋转

c# - 绑定(bind)到 iOS 静态库时从 Monotouch 访问 Objective-C 结构

android - 是否可以仅使用 Assets 文件夹中的一个样式表将自定义 CSS 添加到 Xamarin 中的 WebView?

c# - HttpClient.PutAsync- "Entity only allows writes with a JSON Content-Type header"

javascript - Phonegap应用程序使用localstorage函数错误

Android:我的应用程序中所有微调器的全局样式

c# - 调用从 C# 返回类型的 Oracle 函数