开发者

Urban Airship Tags issue

开发者 https://www.devze.com 2022-12-26 16:38 出处:网络
I modified the alias sample code from: [request addRequestHeader: @\"Content-Type\" value: @\"application/json\"];

I modified the alias sample code from:

    [request addRequestHeader: @"Content-Type" value: @"application/json"];
    [request appendPostData:[[NSString stringWithFormat: @"{\"alias\": \"%@\"}", self.deviceAlias]
                          dataUsingEncoding:NSUTF8StringEncoding]];

to:

[request addRequestHeader: @"Content-Type" value: @"application/json"];
[request appendPostData:[[NSString stringWithFormat: @"{\"tags\": \"%@\"}", offsetStr]
                                                 dataUsingEncoding:NSUTF8StringEncoding]];

开发者_运维百科offsetStr is a string containing a Timezone offset (which can be any number between -12 and 12).

For some reason, Urban Airship is making each character of the string into its own tag.

I've tried to substitute the - for a string neg with the same results.

What's wrong?


The problem is that "tags" should be a list, not a single value. Through square brackets around the value, and you'll be fine.

[request addRequestHeader: @"Content-Type" value: @"application/json"];
[request appendPostData:[[NSString stringWithFormat: @"{\"tags\": [\"%@\]"}", offsetStr]
                                             dataUsingEncoding:NSUTF8StringEncoding]];

But you really should use a JSON library, like json-framework or TouchJSON if you want to encode JSON on the client.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号