我正在向我的 iPhone 应用程序发送推送通知,并且我希望根据应用程序是否已启动来执行一组不同的指令。我是 iPhone 开发新手,虽然我怀疑 UIApplication 或我项目的 AppDelegate 类有解决方案,但我还没有找到好的答案。有没有简单的方法来检查这一点?
最佳答案
Here's the more appropriate way of handling active/inactive state of the app.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
// check for the app state
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive) {
//the app is in the foreground, so here you do your stuff since the OS does not do it for you
//navigate the "aps" dictionary looking for "loc-args" and "loc-key", for example, or your personal payload)
}
application.applicationIconBadgeNumber = 0;
}
didReceiveRemoteNotification:
在应用程序运行时调用,是的,但是当它挂起时,iOS
会负责放置徽章等。如果应用程序在前台,操作系统不执行任何操作,只是调用您的 didReceiveRemoteNotification:
。
关于iphone - 收到推送通知时如何判断我的 iPhone 应用程序是否正在运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1998196/