title: Firebase send push notification from devices (IOS)
body: <p>In ios I am using Firebase database and FCM. I have to send push notification from devices to devices by devices token. I have FCM API "<a href="https://fcm.googleapis.com/fcm/send" rel="nofollow noreferrer">https://fcm.googleapis.com/fcm/send</a>" This is post method and add parameter 
  Like : </p>
  
  <pre><code>Content-Type:application/json
  Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
  
  {
    "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "data" : {
      ...
    },
  }
  </code></pre>
  
  <p>but when I try to call this API this is alway return me an error , and the same API calling from android devices this is working in android, not in ios Here is my code and error, please give me the solution </p>
  
  <pre><code>-(void)sendPush
  {
  
  
  
       NSDictionary *noti = @{@"body": @"This is a Firebase Cloud Messaging Topic Message", @"title": @"high"};
      NSDictionary *data = @{@"text": @"This is a Firebase Cloud Messaging Topic Message", @"title": @"high"};
      NSDictionary *params = @{@"to": @"dbpuoXnzY3o:APA91bH3AE_XCbsLpOXycNULcSh1GHzohEFdopmzkY_n8bm78E9_5fHyY3PLCwi5HtTLU_IoOwfdbDc5qCbyzc6tD9Ahg0EviCfbAmhftmMsPqfi0WC...",@"notification":noti,@"data":data};
      NSLog(@"%@",params);
  
      [NetworkManager postNotification:params getUrl:@"https://fcm.googleapis.com/fcm/send" success:^(id response) {
           NSLog(@"%@",response);
  
  
  
      } failure:^(NSError *error) {
  
      }];
  
  }
  </code></pre>
  
  <p>in nslog this looks like this </p>
  
  <pre><code>{
      data =     {
          text = "This is a Firebase Cloud Messaging Topic Message";
          title = high;
      };
      notification =     {
          body = "This is a Firebase Cloud Messaging Topic Message";
          title = high;
      };
      to = "dbpuoXnzY3o:APA91bH3AE_XCbsLpOXycNULcSh1GHzohEFdopmzkY_n8bm78E9_5fHyY3PLCwi5HtTLU_IoOwfdbDc5qCbyzc6tD9Ahg0EviCfbAmhftmMsPqfi0WC...";
  }
  </code></pre>
  
  <p>Afnetworking calling function </p>
  
  <pre><code> AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc]initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
  
  
      manager.responseSerializer = [AFJSONResponseSerializer
                                    serializerWithReadingOptions:NSJSONReadingAllowFragments];
     // [manager.requestSerializer setValue:@"text/html" forHTTPHeaderField:@"Content-Type"];
      [manager.requestSerializer setValue:@"AIzaSyADxgFPrxx....." forHTTPHeaderField:@"key"];
  
     // NSLog(@"Token==%@",[GeneralSetting sharedInstance].token_number);
      [manager POST:URL parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
          [MBProgressHUD hideHUDForView:appDelegate.window animated:YES];
          success(responseObject);
  
          ////NSLog(@"success!");
      } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
          failure(error);
          [MBProgressHUD hideHUDForView:appDelegate.window animated:YES];
        NSLog(@"error: %@", error.description);
  
          // [self alert:@"" title:@""];
      }];
  </code></pre>
  
  <p>ERROR is </p>
  
  <pre><code>error: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: unauthorized (401)" UserInfo={NSUnderlyingError=0x17024a1d0 {Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/html" UserInfo={com.alamofire.serialization.response.error.response=&lt;NSHTTPURLResponse: 0x17402fa40&gt; { URL: https://fcm.googleapis.com/fcm/send } { status code: 401, headers {
      "Cache-Control" = "private, max-age=0";
      "Content-Encoding" = gzip;
      "Content-Length" = 259;
      "Content-Type" = "text/html; charset=UTF-8";
      Date = "Tue, 04 Jul 2017 10:17:43 GMT";
      Expires = "Tue, 04 Jul 2017 10:17:43 GMT";
      Server = GSE;
      "alt-svc" = "quic=\":443\"; ma=2592000; v=\"39,38,37,36,35\"";
      "x-content-type-options" = nosniff;
      "x-frame-options" = SAMEORIGIN;
      "x-xss-protection" = "1; mode=block";
  } },
  </code></pre>
  
  <p>Please help me , Please give me solution </p>
  
  <p>I have tried from postmen this is working from postmen </p>
  
  <p><a href="https://i.stack.imgur.com/B8YXk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B8YXk.png" alt="enter image description here"></a></p>
  
  <p>same data i am sending from code this is not working may be problem is sending dictionary 
  I am using this code </p>
  
  <pre><code>NSDictionary *noti = @{@"body": @"Hello", @"title": @"This is test message"};
  
      NSDictionary *params = @{@"to": [GeneralSetting sharedInstance].token_number,@"notification":noti};
      NSLog(@"%@",params);
  </code></pre>
  
  <p>AND </p>
  
  <pre><code>[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
      [manager.requestSerializer setValue:@"key=AIzaSy.....tBxdYAIRp2KBG0NoS8dOqgy4" forHTTPHeaderField:@"Authorization"];
  </code></pre>
  
  <p>The Response is </p>
  
  <pre><code>{
      notification =     {
          body = Hello;
          title = "This is test message";
      };
      to = "dQgCDOK3sec:APA91zFbkqkgyTNrsYsEmUJwpCtMs1VAmXF9DpF_zQfBYui3UjCA9nYtS_TK549RPnlWEfe-jSvD9MMc3lTFNsGJlyIOqNm84s8GoW1LfTGG0geuWEclb";
  }
  
   Request failed: bad request (400)
  </code></pre>