应用程序未运行时处理推送通知(即完全被杀死) [英] Handling Push Notifications when App is NOT running (i.e Totally Killed)

查看:127
本文介绍了应用程序未运行时处理推送通知(即完全被杀死)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以将推送通知发送到我的IOS设备。但是,当我点击该通知时,它只会打开应用程序。应用内没有显示任何消息。

I'm able to send push notifications to my IOS device. But when I click on that notification it just opens the app. No message is shown inside the app.

我使用的代码:

if (application.applicationState == UIApplicationStateActive) {

    NSString *cancelTitle = @"Close";

    NSString *showTitle = @"Show";

    NSString *message = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];

    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Some title"

                                                        message:message

                                                       delegate:self

                                              cancelButtonTitle:cancelTitle

                                              otherButtonTitles:showTitle, nil];

    [alertView show];

    [alertView release];

} else {

    //Do stuff that you would do if the application was not active

}

但无法在上述代码的帮助下显示我的消息。以上代码仅在我的应用程序处于打开状态时处于前台状态,而不是仅显示此警报。

But unable to show my message with the help of above code. Above code only works when my app is open that is in foreground state than only this alert gets displayed else not.

请帮助。

谢谢。

推荐答案

当应用程序被完全杀死时获取通知代码

When application is totally killed get notification code

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (launchOptions != nil)
{
     //opened from a push notification when the app is closed
    NSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    if (userInfo != nil)
    {
         NSLog(@"userInfo->%@",[userInfo objectForKey:@"aps"]);
         //write you push handle code here

    }

}
}

欲了解更多信息,请访问以下链接:在应用程序终止时处理推送通知

For more go through this link: Handling Push Notifications when App is Terminated

这篇关于应用程序未运行时处理推送通知(即完全被杀死)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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