当用户按下图标而不是警报时处理本地通知 [英] Handling local notifications when the user presses the icon instead of the alert

查看:47
本文介绍了当用户按下图标而不是警报时处理本地通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我想处理的引用自 Apple 文档的情况.

Here is the situation that I want to handle quoted from Apple's documentation.

作为显示通知的结果,用户点击警报的操作按钮或点击(或点击)应用程序图标.如果点击操作按钮(在运行 iOS 的设备上),系统启动应用程序,应用程序调用其委托的 application:didFinishLaunchingWithOptions: 方法(如果已实现);它传入通知负载(用于远程通知)或本地通知对象(用于本地通知).

As a result of the presented notification, the user taps the action button of the alert or taps (or clicks) the application icon. If the action button is tapped (on a device running iOS), the system launches the application and the application calls its delegate’s application:didFinishLaunchingWithOptions: method (if implemented); it passes in the notification payload (for remote notifications) or the local-notification object (for local notifications).

如果在运行 iOS 的设备上点击应用程序图标,应用程序将调用相同的方法,但不提供有关通知的信息.如果在运行 OS X 的计算机上单击应用程序图标,应用程序将调用委托的 applicationDidFinishLaunching: 方法,委托可以在该方法中获取远程通知负载.

如果没有通知的信息,我该如何处理?

How do I handle this situation if there is no information about the notification?

推荐答案

如果我没理解错的话,听起来你有一个 UILocalNotification 被触发了,但如果用户点击应用程序图标,你仍然需要处理它的通知.正确吗?

If I understand you correctly, it sounds like you have a UILocalNotification that has been fired, but you need to still handle it if the user taps the application icon instead of the notification. Correct?

如果是这种情况,那么据我所知,您将无法处理来自应用程序委托的通知,因为应用程序不是通过通知启动或带出后台的,而是由用户的互动.

If this is the case, then to my knowledge you won't be able to handle the notification from the app delegate, because the app is not being launched or brought out of the background by the notification, but instead by the user's interaction.

但是,如果您在带有通知的应用程序上设置了一个徽章编号,那么您可以尝试这样的操作:

However, if you are setting a badgeNumber on the application with the notification then you could try something like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (launchOptions[UIApplicationLaunchOptionsLocalNotificationKey]) {
    UILocalNotification *notification = launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];
} else if ([UIApplication sharedApplication].applicationIconBadgeNumber > 0) {
    // Assume that user launched the app from the icon with a notification present.
}}

您可能还需要检查 - (void)applicationDidBecomeActive:(UIApplication *)application 中的徽章编号.

You may also have to check the badgeNumber in - (void)applicationDidBecomeActive:(UIApplication *)application as well.

这篇关于当用户按下图标而不是警报时处理本地通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆