gpt4 book ai didi

ios - 在 iOS 中解析 moengage 通知响应时出现问题?

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

我在解析下面的 Moengage 通知响应时遇到问题

来自:

   -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
{
NSLog(@"notification appdelegate %@",userInfo);
[self customPushHandler:userInfo];

}

通知应用委托(delegate):
{
“app_extra”= {
屏幕数据 = {
""= "";
};
屏幕名称 = "";
};
应用程序 = {
alert = "iOS 测试";
角标(Badge) = 1;
“内容可用”= 0;
声音=默认;
};
moengage = {
""= "";
西德=;
};
}

- (void) customPushHandler:(NSDictionary *)notification {

if (notification !=nil && [notification objectForKey:@"app_extra"] != nil) {
NSDictionary* app_extra_dict = [notification objectForKey:@"app_extra"];

NSDictionary* app_extra_dict1 = [[notification objectForKey:@"app_extra"]objectForKey:@"aps"];

NSDictionary* app_extra_dict2 = [[notification objectForKey:@"aps"];

NSLog(@"Moenage notification %@",notification);
NSLog(@"Menage apps %@",app_extra_dict1);
NSLog(@"Moenage apps %@",app_extra_dict2);
NSLog(@"Moenage %@",app_extra_dict );

}
}

日志:

Moengage notification :Same as above response

Menage apps (null)

Moenage apps (null)

Moenage:

{
屏幕数据 = {
""= "";
};
屏幕名称 = "";
}

现在我的问题是我正在尝试检索“aps = { alert = "iOS Test ";"..但这不是 JSON..任何人都可以建议我解析这个响应或者是他们从这个响应中检索 "iOS test"

最佳答案

您获取数据的格式没有问题,无需转换为 JSON,您已经在 NSDictionary 中获取数据。您将字典转换为 JSON 并再次转换 JSON 以获得相同字典的答案没有任何意义。您可以使用以下键简单地访问所有值:

- (void) customPushHandler:(NSDictionary *)notification {

if (notification !=nil && [notification objectForKey:@"app_extra"] != nil) {

NSDictionary* app_extra_dict = [notification objectForKey:@"app_extra"];
NSDictionary* aps_dict = [notification objectForKey:@"aps"];

NSLog(@"Moengage notification : %@",notification);
NSLog(@"Moengage appsExtra : %@",app_extra_dict);
NSLog(@"Moengage aps : %@",aps_dict);
}
}

下面是相同的日志:

    Moengage notification :  {
"app_extra" = {
screenData = {
key1 = Val1;
};
screenName = Screen1;
};
aps = {
alert = "Hello!!!";
badge = 1;
"content-available" = 0;
sound = default;
};
moengage = {
cid = 5715f243597b7b0f37a9254a;
key1 = Val1;
};
}

Moengage appsExtra : {
screenData = {
key1 = Val1;
};
screenName = Screen1;
}

Moengage aps : {
alert = "Hello!!!";
badge = 1;
"content-available" = 0;
sound = default;
}

关于ios - 在 iOS 中解析 moengage 通知响应时出现问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35078341/

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