本文介绍了收到推送通知时,如何知道我的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词典中.如果字典为零,则用户可以正常点击该应用程序图标.

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

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

08-23 07:32