【发布时间】:2012-09-19 14:00:03
【问题描述】:
我正在尝试使用远程通知处理所有可能的情况。 当应用程序在前台时我很好 - didReceiveRemoteNotification 被调用。 问题是当应用程序处于后台状态时,我收到推送通知。 什么都没有被调用。 当应用回到前台时如何让用户知道他有新的远程通知?
【问题讨论】:
标签: ios apple-push-notifications
我正在尝试使用远程通知处理所有可能的情况。 当应用程序在前台时我很好 - didReceiveRemoteNotification 被调用。 问题是当应用程序处于后台状态时,我收到推送通知。 什么都没有被调用。 当应用回到前台时如何让用户知道他有新的远程通知?
【问题讨论】:
标签: ios apple-push-notifications
您拦截推送通知的唯一方法是当用户点击通知中心的通知时(或从锁定屏幕滑动应用程序图标时)。
在这种情况下,在应用程序进入前台之前调用应用程序委托中的didFinishLaunchingWithOptions 方法。您应该使用NSDictionarylaunchOptions来确定应用程序是从通知中心启动还是通过点击图标启动(正常使用)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSDictionary *pushDic = [launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];
if (pushDic != nil) {
NSLog(@"Notification");
}
else {
}
}
【讨论】:
看看编程指南:
如果点击操作按钮(在运行 iOS 的设备上),系统将启动应用程序并且应用程序调用其委托的 application:didFinishLaunchingWithOptions: 方法(如果已实现);它传入通知负载(用于远程通知)或本地通知对象(用于本地通知)。
【讨论】:
The user launched the application in response to the arrival of a remote notification. In this case, the dictionary contains the notification payload dictionary described in the application:didReceiveRemoteNotification: method. (Key: UIApplicationLaunchOptionsRemoteNotificationKey)
当然,如果您的应用在后台,则不会有任何调用...
如果您的应用没有启动(甚至没有在后台暂停),
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
将包含通知负载(键 UIApplicationLaunchOptionsRemoteNotificationKey):
NSDictionary *remoteNotification = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
【讨论】: