title: Push notification message not received in iOS
body: <p>I am using push notification in my iOS app.</p>
  
  <p>I cant able to get the push notification message from the server. But i can get the message when using third party server APN Tester free.</p>
  
  <p>In my app i am using backend as .net webservice (i.e asmx file). Below are the code i am using for push notification.</p>
  
  <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  
  
  [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
  [[UIApplication sharedApplication] registerForRemoteNotifications];
  
  NSLog(@"didFinishLaunchingWithOptions");
  
  return YES;
  }
  /-(void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
  {
  NSLog(@"My token is: %@", deviceToken);
  
  NSString *deviceTokenString = [NSString stringWithFormat:@"%@", deviceToken];
  
  NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken");
  
  NSLog(@"My token is: %@", deviceTokenString);
  
  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:deviceTokenString
                                                  message:@"devicetoken"
                                                 delegate:self
                                        cancelButtonTitle:@"OK"
                                        otherButtonTitles:nil];
  [alert show];
  
  /
  }*/
  - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
  {
  NSLog(@"My token is: %@", deviceToken);
  _token_data =deviceToken;
  
  
  NSString *title = [NSString stringWithFormat:@"%@",_token_data];
  NSString *trimmedString = [title stringByReplacingOccurrencesOfString: @" " withString:@""];
  trimmedString = [trimmedString stringByReplacingOccurrencesOfString: @"&lt;" withString:@""];
  trimmedString = [trimmedString stringByReplacingOccurrencesOfString: @"&gt;" withString:@""];
  
  _tokenkey = [[NSString alloc] initWithData:deviceToken encoding:NSUTF8StringEncoding];
  
  NSString *soapFormat = [NSString stringWithFormat:@"&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n"
                          "&lt;soap:Envelope xmlns:xsi=\"http:/
                          "&lt;soap:Body&gt;\n"
                          "&lt;AddAppleDeviceToken xmlns=\"http:/
                          "&lt;PortalId&gt;0&lt;/PortalId&gt;\n"
                          "&lt;ModuleId&gt;12&lt;/ModuleId&gt;\n"
                          "&lt;strDeviceToken&gt;sdfssdfs&lt;/strDeviceToken&gt;\n"
                          "&lt;/AddAppleDeviceToken&gt;\n"
                          "&lt;/soap:Body&gt;\n"
                          "&lt;/soap:Envelope&gt;\n"];
  
  NSURL *locationOfWebService = [NSURL URLWithString:@"http://www.mywebsite.com/push.asmx"
  
  wsDeviceToken.asmx"];
  
  NSMutableURLRequest *theRequest = [[NSMutableURLRequest alloc]initWithURL:locationOfWebService];
  NSString *msgLength = [NSString stringWithFormat:@"%lu",(unsigned long)[soapFormat length]];
  [theRequest addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
  [theRequest addValue:@"http:/
  [theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
  [theRequest setHTTPMethod:@"POST"];
  /
  [theRequest setHTTPBody:[soapFormat dataUsingEncoding:NSUTF8StringEncoding]];
  NSURLConnection *connect = [[NSURLConnection alloc]initWithRequest:theRequest delegate:self];
  NSLog(@"soapFormat %@",soapFormat);
  if (connect) {
      _webData = [[NSMutableData alloc]init];
      NSLog(@"Connection Establish");
  }
  else {
      NSLog(@"No Connection established");
  }
  
  NSString * test = [NSString stringWithFormat:@"Your Device token is %@", trimmedString];
  
  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:test
                                                  message:@"devicetoken"
                                                 delegate:self
                                        cancelButtonTitle:@"OK"
                                        otherButtonTitles:nil];
  [alert show];
  }
  - (void)application:(UIApplication *)application     didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
  if (notificationSettings.types != UIUserNotificationTypeNone) {
      NSLog(@"didRegisterUser");
      [application registerForRemoteNotifications];
  
      UIAlertView *alert33 = [[UIAlertView alloc] initWithTitle:@"didRegisterUser"
                                                        message:@"didRegisterUser"
                                                       delegate:self
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
      [alert33 show];
  }
  }
  - (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
   {
  NSLog(@"Failed to get token, error: %@", error);
  }
  - (void)application:(UIApplication *)application
  didReceiveRemoteNotification:(NSDictionary *)userInfo
  {
  /
  /
  NSString *message = [[userInfo objectForKey:@"aps"]
                       objectForKey:@"alert"];
  UIAlertView *alert = [[UIAlertView alloc]
                        initWithTitle:@""
                        message:message
                        delegate:nil
                        cancelButtonTitle:@"OK"
                        otherButtonTitles:nil];
  [alert show];
  /
  }
  #pragma - NSURLConnection delegate method
  -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
  {
  [_webData setLength: 0];
  NSHTTPURLResponse * httpResponse;
  httpResponse = (NSHTTPURLResponse *) response;
  NSLog(@"HTTP error %zd", (ssize_t) httpResponse.statusCode);
  }
  -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
  {
   [_webData appendData:data];
  }
  -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
  {
  NSLog(@"ERROR with theConenction");
  }
  -(void)connectionDidFinishLoading:(NSURLConnection *)connection
  { NSLog(@"DONE. Received Bytes: %lu", (unsigned long)[_webData length]);
  self.xmlParser = [[NSXMLParser alloc]initWithData:_webData];
  [self.xmlParser setDelegate: self];
  [self.xmlParser parse];
   }
  -(void) parser:(NSXMLParser *) parser didStartElement:(NSString *) elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *) qName attributes:(NSDictionary *) attributeDict {
  }
   -(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
  if ([elementName isEqualToString:@"AddAppleDeviceTokenResult"]) {
      NSString *tmpstr = [[NSString alloc] init];
      tmpstr = [tmpstr stringByAppendingString:soapResults];
      [soapResults setString:@""];
      NSLog(@"AddAppleDeviceTokenResult %@",tmpstr);
  
      if([tmpstr isEqualToString:@"DeviceToken Added in Database"])
      {
  
          NSString * test = [NSString stringWithFormat:@"Your Device token is added in database"];
  
          UIAlertView *alert = [[UIAlertView alloc] initWithTitle:test
                                                          message:_tokenkey
                                                         delegate:self
                                                cancelButtonTitle:@"OK"
                                                otherButtonTitles:nil];
          [alert show];
          NSLog(@"Token added successfully");
  
          [[NSUserDefaults standardUserDefaults]setValue:@"1" forKey:@"isDeviceTokenAdded"];
          [[NSUserDefaults standardUserDefaults]synchronize];
      }
  }
  }
  -(void)parser:(NSXMLParser *) parser foundCharacters:(NSString *)string {
  if (!soapResults) {
      /
      soapResults = [[NSMutableString alloc] init];
      NSLog(@"soapResults %@",soapResults);
  }
  if([string length] &gt; 0){
      NSString *cleanString = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
      if([cleanString length] &gt;0){
          [soapResults appendString: string];
      }
  }
  }
  </code></pre>
  
  <p>Any suggessions Please.</p>
  
  <p>Thanks in advance.</p>