收到推送通知时,如何判断我的 iPhone 应用程序是否正在运行? [英] How do I tell if my iPhone app is running when a Push Notification is received?

查看:32
本文介绍了收到推送通知时,如何判断我的 iPhone 应用程序是否正在运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向我的 iPhone 应用程序发送推送通知,我希望根据应用程序是否已启动来执行一组不同的指令.我是 iPhone 开发的新手,虽然我怀疑 UIApplication 或我项目的 AppDelegate 类有解决方案,但我还没有找到好的答案.有没有简单的方法来检查这个?

I am sending Push Notifications to my iPhone app, and I'd like a different set of instructions to execute depending on whether the app is already launched or not. I'm new to iPhone development, and while I suspect UIApplication or my project's AppDelegate class has the solution, I haven't found a good answer. Is there an easy way to check for this?

推荐答案

UIApplication委托有方法

The UIApplication delegate has the method

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

您需要实施.这会在应用程序运行时收到通知.

which you need to implement. This receives the notification when the app is running.

如果您的应用程序当前未运行并且收到通知,则可以使用

If your app is not currently running and a notification is received then your app can be launched with

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

包含在 launchOptions 字典中的通知详细信息.如果字典为 nil,则用户照常点击应用程序图标.

with the notification details held in the launchOptions dictionary. if the dictionary is nil then the user tapped the application icon as normal.

这篇关于收到推送通知时,如何判断我的 iPhone 应用程序是否正在运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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