在 UIAlertView 中显示推送通知的内容 [英] Show the content of push notification in UIAlertView

查看:43
本文介绍了在 UIAlertView 中显示推送通知的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个应用程序,其中我已激活推送通知.我使用 parse.com.到目前为止,我已经让它工作了,我可以发送通知并且设备收到它,我还在应用程序上获得了一个徽章.当您从通知进入应用程序时,我已经设置了 AlertView.但我不知道如何在 UIAlertView 中显示推送通知的文本.我还希望徽章在您查看消息后消失.这是我使用的代码:

Hi Im currently developing an app where i have push notifications activated. I use parse.com. I have got it working so far that i can send a notification and the device receives it and i also get a badge on the app. And i have set an AlertView when you enter the app from the notification. But i dont know how to display the text of the push notification in the UIAlertView. And i also want the badge to disappear when you've viewed the message. Here is the code Im using:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
if (application.applicationState == UIApplicationStateInactive)
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Text" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];

    [alert show];
}
else if (application.applicationState == UIApplicationStateActive)
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Text" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];

    [alert show];
}
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

{
    NSDictionary * pushDictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

    if (pushDictionary)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Text" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];

        [alert show];
    }
}

推荐答案

要处理推送通知并显示带有其信息的警报视图,请尝试在 appDelegate 中尝试:

To handle the Push Notification and show an Alert View with its info try in appDelegate:

- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {     
   [PFPush handlePush:userInfo];  
}

这篇关于在 UIAlertView 中显示推送通知的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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