Send Push Notification to User Devices - Objective C

Source Code:

  
 

                        #import <Foundation/Foundation.h>

NSDictionary *headers = @{ @"content-type": @"application/x-www-form-urlencoded",
                           @"cache-control": @"no-cache" };

NSMutableData *postData = [[NSMutableData alloc] initWithData:[@"api_key=YOUR-API-KEY" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&user_id=YOUR-CUSTOM-USER-ID" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&msg_title=test message" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"&destination_url=https://pushnotificationapi.com" dataUsingEncoding:NSUTF8StringEncoding]];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://send.pushnotificationapi.com/v1/push/send_by_userid"]
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"%@", httpResponse);
                                                }
                                            }];
[dataTask resume];