在UIAlertView中显示推送通知文本

时间:2014-11-23 21:55:11

标签: ios objective-c parse-platform apple-push-notifications

我正在使用Parse向我的应用发送推送通知。我想要的是,当用户从锁定屏幕滑动通知或从主屏幕点击它时,它打开应用程序并在UIAlert视图中显示推送通知的文本。

我想它会插入app delegate的didfinishlaunchingwithoptions方法,但我真的不知道如何提取警报文本。

非常感谢任何建议。

以下是我显示警报的代码 - 它正在运行,但它显示完整的JSON消息 - 当我尝试使用objectForKey:@“alert语句尝试仅提取”警报“部分时推送通知,警报的消息部分中不显示任何内容。

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    [PFPush handlePush:userInfo];
    pushText = [userInfo objectForKey:@"alert"];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"News", "")
                                                    message:pushText
                                                   delegate:nil
                                          cancelButtonTitle:@"Ok"
                                          otherButtonTitles: nil];
    [alert show];




}

1 个答案:

答案 0 :(得分:1)

您可以将此代码放入didFinishLaunchingWithOptions部分,然后在UIAlertView中显示pushText变量。

NSDictionary *notifKey = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];

if (notifKey)
{
    pushText = [notifKey objectForKey:@"alert"];
}