当应用程序从后台被杀时,Iphone上的通知

时间:2015-04-07 10:38:00

标签: ios iphone notifications

我正在开发一个iPhone应用程序,其中有一个服务器发送推送通知,该通知只是为了暗示新消息已到达。

来自服务器的通知如下所示:

  

{" LAST_UPDATED":" 2015年4月7日:15:00:00"" APS" {"徽章" :2," alert":{" action-loc-key":" Open"," body":"新消息& #34;}"内容可用":1}}

如果应用程序在后台运行,我可以从服务器中提取确切的消息,然后我会显示带有确切消息的本地通知。

但是如果应用程序没有在后台运行,则会显示来自服务器的通知。

我该如何处理这种情况?

2 个答案:

答案 0 :(得分:0)

如果您的应用程序未运行,iOS会收到通知并显示徽章或警告(取决于您的registerUserNotificationSettings设置)。当用户打开时,通知将重定向到您的应用程序。

之后,您可以使用以下代码处理didFinishLaunchingWithOptions方法的通知:

//App Launched from Push Notification
NSDictionary *remoteNotification = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
if (remoteNotification)
{
    //Handle your notification
    NSLog(@"App Launched from Push Notification");
}

答案 1 :(得分:0)

尝试交互式推送通知。应用程序不会自动启动,但您只需单击通知按钮即可执行小任务(可在几毫秒内完成)。