得到推送通知,而应用程序是不是乳宁iPhone [英] get push notification while the app is not runing iPhone

查看:126
本文介绍了得到推送通知,而应用程序是不是乳宁iPhone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作在一个iPhone应用程序,其中包括推送通知。正如我在许多文件和教程已经看到它表明了推送通知与注册

I am working on one iPhone app which involves a push notification. As I have seen in many documents and tutorials it suggests to register for push notification with in

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

这样的:

  - (BOOL)application:(UIApplication *)application 
  didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
   {   
   [[UIApplication sharedApplication]    registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert| UIRemoteNotificationTypeBadge|  UIRemoteNotificationTypeSound ]; 

  .........
  } 

现在的问题是,如果应用程序没有(甚至在后台)运行,当推来了,它不能处理推送消息,但如果我再次使用推送消息从通知区域和午餐的应用程序再次,我可以让我的消息。

now the question is, if the app was not running (even in background), when the push come, it cant process the push message, but if I use the push message again from the notification area and lunch the app again, I can get my message.

我需要做的,使我的应用程序得到推送消息,即使它的午餐是第一次?

what I need to do to make my app get the push message even when it lunch for the first time?

感谢

推荐答案

您可能会被混为一谈注册并接收通知的概念。这是不可能的一个应用程序的 registerForRemoteNotificationTypes前收到一个推送通知:方法被称为第一次,因为这种方法提供了一个用于发送推送通知在推令牌位居第一。

You might be conflating the notion of registering for and receiving notifications. It is impossible for an app to receive a push notification before the registerForRemoteNotificationTypes: method is called the first time, since this method provides the push token that is used to send push notifications in the first place.

所以,你必须谈论下,他们可以交付两个独立的情况下收到通知:在初始应用程序启动,程序的执行过程中

So, you must be talking about receiving notifications under the two separate situations in which they can be delivered: upon initial app launch, and during the execution of the program.

为了处理第一类的通知,你必须检查选项字典发送到的application:didFinishLaunchingWithOptions:。下面code说明了如何将在发射的委托方法收到通知时,推送通知到达而应用程序已经在运行时调用。

In order to handle notifications of the first type, you must inspect the options dictionary sent to application:didFinishLaunchingWithOptions:. The following code shows how to route a notification received at launch to the delegate method that is called when a push notification arrives while the app is already running.

这将在你的的application:didFinishLaunchingWithOptions:覆盖:

NSDictionary *pushNotificationPayload = [launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if(pushNotificationPayload) {
    [self application:application didReceiveRemoteNotification:pushNotificationPayload];
}

这篇关于得到推送通知,而应用程序是不是乳宁iPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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