views:

114

answers:

1

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?

+3  A: 

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.

robotadam
Just want to send timezone offset. Thanks.
Moshe