iOS版:处理远程(推送)的通知 [英] iOS: Handling Remote (push) Notifications

查看:228
本文介绍了iOS版:处理远程(推送)的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图处理所有可能的情况下,远程通知。
我很确定,当在前台应用程序 - didReceiveRemoteNotification被调用。
问题是,当应用程序在后台状态,我收到推送通知。
没有被调用。
如何让用户知道他有新的远程通知,当应用程序回到前台?

I'm trying to handle all possible cases with remote notifications. I'm ok when app in foreground - didReceiveRemoteNotification is called. The problem is when app in background state, and I receive push notification. Nothing is called. how to let user know that he has new remote notification when app come back to foreground ?

推荐答案

为您拦截推送通知的唯一途径是当用户敲击在通知中心的通知(或当幻灯片从锁定屏幕应用程序图标)

The only way for you to intercept a push notification is when the user tap the notify in the notification center (or when slide the app icon from the lock screen).

在这种情况下,应用程序在前台走在应用程序委托 didFinishLaunchingWithOptions 方法之前被调用。您应该使用的NSDictionary launchOptions 来确定应用是否已经从通知中心,或通过点击图标(推出正常使用)

In this case before the app go in foreground the didFinishLaunchingWithOptions method in the app delegate is called. You should use the NSDictionary launchOptions to determine if the app has been launched from notification center or by tapping the icon (the normal use)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSDictionary *pushDic = [launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];
    if (pushDic != nil) {
        NSLog(@"Notification");
    }
    else {

    }
}

这篇关于iOS版:处理远程(推送)的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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