gpt4 book ai didi

ios - 在 UIAlert View 中显示推送通知文本

转载 作者:行者123 更新时间:2023-11-29 02:29:24 27 4
gpt4 key购买 nike

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

我想它会插入应用程序委托(delegate)的 didfinishlaunchingwithoptions 方法中,但我真的不知道如何提取警报文本。

如有任何建议,我们将不胜感激。

下面是我显示警报的代码 - 它正在工作,但它显示完整的 JSON 消息 - 当我尝试使用 objectForKey:@"alert 语句来尝试仅提取 "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];




}

最佳答案

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

NSDictionary *notifKey = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];

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

关于ios - 在 UIAlert View 中显示推送通知文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27094831/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com