gpt4 book ai didi

iphone - 如何从推送通知中获取文本字符串?

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

我有一个 Iphone 应用程序,在其中我正在从服务器接收推送通知。现在我将转到 View Controller 来显示消息。相同的消息加载在 TableView 中。所以这不是问题。现在我我收到两种消息,一种是链接,另一种是之前的消息。如果是链接,我想在 saffari 中打开它,不需要像往常一样进入桌面 View 。任何人都可以帮助我实现这一目标吗?

最佳答案

当您单击推送通知时,您会在函数中获得一个字典 - didReceiveRemoteNotification:

试试这个代码:-

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(@"remote notification: %@",[userInfo description]);

if (userInfo)
{
if ([[userInfo allKeys] containsObject:@"aps"])
{
if([[[userInfo objectForKey:@"aps"] allKeys] containsObject:@"alert"])
{
if([[[userInfo objectForKey:@"aps"] allKeys] containsObject:@"alert"])
{
NSString *urlString = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];
NSURL *url = [NSURL URLWithString:urlString];

if(url)
{
[[UIApplication sharedApplication]openURL:url]; // open in the safari...
}

else
{
// use the message in table view


}

}

}
}
}


}

关于iphone - 如何从推送通知中获取文本字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12742489/

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