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

If you already have an Apple ID, proceed to the Generating a certificate from Keychain access procedure.

Procedure

  1. Open https://developer.apple.com/and log in using your credentials.
  2. Select Certificates, Identifiers and Profiles.
  3. From the dropdown menu, select iOS.
  4. From the side menu, select App IDs and create a new App ID.
  5. To complete the app registration, click Register > Done.

Results

The newly created App apears in the list of App IDs.

Generating a certificate from Keychain access

Procedure

  1. On your Mac OS X, launch the Keychain Access application.
  2. Select Keychain Access > Certificate Assistant > Request a Certificate from a Certificate Authority.
  3. Save the certificate.

Generating a Production+SSL certificate

About this task

Note: Currently, Unica Deliver only supports Production certificate.

Procedure

  1. Access the https://developer.apple.com/ again and log in using your credentials.
  2. Select the app that you created in procedure Creating an Apple ID and click Edit.
  3. Scroll down to the Production+SSL certificates section and click Create Certificate.
  4. Click Continue.
  5. Select the certificate that you created using the Generating a certificate from Keychain access procedure and click Continue.
  6. Download the Production Certificate.
  7. To finish the procedure, click Done.

Generating an APNS .p12 certificate

Procedure

  1. Double-click the Production Certificate that you created in the Generating a Production+SSL certificate procedure to add it to the Keychain Access.
  2. From the side menu, navigate to Keychain Access > Login Keychain > My Certificate.
  3. Locate the certificate and right-click the certificate to export it.
  4. Type the certificate name and click Save.
  5. Type the password for the certificate and click OK.
  6. To finish the procedure, type your system's administrator password and press Enter.

Results

Provide this Certificate key to the Unica Deliver Administrator as part of the Application configuration for Push Notification for iOS.
Note: Create Separate Certificates for Production mode and Development mode for APNS Interaction.

Basic Push with image and customizing the Notification

About this task

You can customize a specific push notification. To customize a specific push notification, use the 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

Use the default iOS framework NSUrl Session for all API calls and post the data back to server.
Sample code for NSurl session for a data 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); 
		}
	}
];