iOS Push integration with APNS
Apple Push Notification Service, also known as Apple Notification Service or APNS, is a platform service from Apple Inc. Third-party application developers use APNS to send push notifications to iOS users. A paid Apple Developer account is mandatory for creating certificates. The steps to create a .p12 certificate, for sending Push notifications, are as follows:
Creating an Apple ID
About this task
Procedure
- Open https://developer.apple.com/and log in using your credentials.
- Select Certificates, Identifiers and Profiles.
- From the dropdown menu, select iOS.
- From the side menu, select App IDs and create a new App ID.
- To complete the app registration, click .
Results
Generating a certificate from Keychain access
Procedure
- On your Mac OS X, launch the Keychain Access application.
- Select .
- Save the certificate.
Generating a Production+SSL certificate
About this task
Procedure
- Access the https://developer.apple.com/ again and log in using your credentials.
- Select the app that you created in procedure Creating an Apple ID and click Edit.
- Scroll down to the Production+SSL certificates section and click Create Certificate.
- Click Continue.
- Select the certificate that you created using the Generating a certificate from Keychain access procedure and click Continue.
- Download the Production Certificate.
- To finish the procedure, click Done.
Generating an APNS .p12 certificate
Procedure
- Double-click the Production Certificate that you created in the Generating a Production+SSL certificate procedure to add it to the Keychain Access.
- From the side menu, navigate to .
- Locate the certificate and right-click the certificate to export it.
- Type the certificate name and click Save.
- Type the password for the certificate and click OK.
- To finish the procedure, type your system's administrator password and press Enter.
Results
Basic Push with image and customizing the Notification
About this task
UNNotificationCategory to define a type of notification that
the executable can receive.In the configureNotification method, add the
UNNotificationCategory and
UNNotificationAction to the custom push.
Create a Swift class and add the Extension class with the Key Name to Send an Image with Simple Push.
Use the following extension for adding the user information with the Key required for customization:
extension UNNotificationRequest
{
var attachment: UNNotificationAttachment?
{
guard let attachmentURL = content.userInfo["image"] as? String, let imageData = try? Data(contentsOf: URL(string: attachmentURL)!)
else
{
return nil
}
return try? UNNotificationAttachment(data: imageData, options: nil)
}
} API calls inside the project
About this task
NSString *strUrl = [NSString stringWithFormat:yourUrl];
NSURL *url = [NSURL URLWithString:strUrl];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response,
NSData *data, NSError *connectionError)
{
if (data.length > 0 && connectionError == nil)
{
NSDictionary *dicResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL];
NSLog(@"%@",dicResponse);
}
}
];