Cannot send PUSH from my iOS app

I'm trying to send a PUSH via Urban Airship using code in my app. 

I can't seem to find any solid documentation on how to do this. I've tried approaches from posts on StackOverflow, this one being the most promising: how to send push from iphone via urban airship?

However, following the approach in that post I am getting a 401 error (401 Unauthorized – The authorization credentials are incorrect)

For the auth, I am using the App Key and App Secret. I read on a c# board, that using the App Master Secret as the password will work as expected. 

When I tried that approach, I received a 400 error: 400 Bad Request – The request body was invalid, either due to malformed JSON or a data validation error. See the response body for more detail.


Thank you for your time.

Didn't find what you were looking for?

New post



  • Hi Brian,

    You should use the Master Secret when making a Push Request. The App Secret is for request made from the device rather than the server.

    Can you paste your request payload body here, so I can take a look?

    Thank you,
    Sean Conlin
    Urban Airship Technical Support
    Portland, Oregon

    Comment actions Permalink
  • Hi Sean,


    Here is the code I am using in the app: 


        NSDictionary *push = @{


                               @"audience" : @{

                                       @"tags" : @[user]


                               @"device_types" : @[ @"ios" ],

                               @"notification" : @{

                                       @"ios" : @{

                                               @"alert":@"This is a test",





                               @"message": @{

                                       @"title": @"This is a test message",

                                       @"body": @"This is a test",

                                       @"content_type": @"text/html",

                                       @"extra": @{

                                               @"offer_id" : @"608f1f6c-8860-c617-a803-b187b491568e"






        NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@""]];

        [request setHTTPMethod:@"POST"];

        [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

        [request setValue:@"application/vnd.urbanairship+json; version=3;" forHTTPHeaderField:@"Accept"];


        NSString *authStr = [NSString stringWithFormat:@"%@:%@",appKey, appSecret];

        NSData *authData = [authStr dataUsingEncoding:NSASCIIStringEncoding];

        NSString *authValue = [NSString stringWithFormat:@"Basic %@", [authData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed]];

        [request setValue:authValue forHTTPHeaderField:@"Authorization"];

        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:push

                                                           options:0 // Pass 0 if you don't care about the readability of the generated string



        request.HTTPBody = jsonData;


        [NSURLConnection connectionWithRequest:request delegate:self];

    Comment actions Permalink

Please sign in to leave a comment.