我如何了解通知导致应用程序处于什么状态?
我设置了一个 UILocalNotification,据我所知,我有 5 种不同的场景:
- 应用程序未运行,用户选择查看通知,因此它启动应用程序。
- 应用程序未运行,用户选择关闭通知,然后稍后打开应用程序。
- 该应用程序在后台运行,用户选择查看通知,因此会将应用程序带到前台。
- 该应用程序在后台运行,用户选择关闭通知,然后打开应用程序,稍后将其带到前台。
- 该应用程序正在前台运行。
我该如何处理这 5 种不同的情况?
I have a UILocalNotification set up, and as far as i can see it i have 5 different scenarios:
- The app is not running, the user chooses to view the notification, so it launches the app.
- The app is not running, the user chooses to close the notification, then opens the app at a later date.
- The app is running in the background, the user chooses to view the notification, so it brings the app to the foreground.
- The app is running in the background, the user chooses to close the notification, then opens the app bringing it to the foreground at a later date.
- The app is running in the foreground.
How do i deal with these 5 different scenarios?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将代码放入
application:didFinishLaunchingWithOptions:
中。在使用
NSDictionary
操作您将找到有关通知。
您可以再次检查
application:didFinishLaunchingWithOptions:
如果本地通知仍处于活动状态并采取适当的操作。
将您的代码放入
applicationWillEnterForeground:
同样的位置,只需检查是否有活动的本地通知。
在这里您可以签入
application:didReceiveLocalNotification:
并通知或不通知用户。Put your code into
application:didFinishLaunchingWithOptions:
. Inthe actions
NSDictionary
you will find the information about thenotification.
You can again check in
application:didFinishLaunchingWithOptions:
if the localnotification is still active and take appropriate action.
Put your code into
applicationWillEnterForeground:
Again the same spot, just check if there are active local notifications.
Here you can check in
application:didReceiveLocalNotification:
and either notify the user or not.不太确定您在追求什么,但以下内容可能会回答您的问题。
来自文档:
Not exactly sure what you're after, but the following might answer your question.
From the documentation: