Push Notification Service
Increase User
Engagement
Calendar Events
Message
Pop-Up
Latest
Updates
Push Notifications
Benefits of Push Notification
Increases user-engagement
e.g. In a turn-based game like Tic-Tac-Toe, it can notify a user of his turn (suppose
he gets a phone call in between and forgets that he was playing!!)
Allows to send messages to users even when the app is not running; thus helps in
reminding them of your App
Helps to build a fan community around your game by pushing to a targeted
audience – like your regular gamers
Allows an App to notify its users of new events without needing to actually open it,
i.e. by a sound or a screen pop up
Coming Soon!! &
App42 Push Notification supports
Our Push Notification API can be used to send cross-
platform push messages to devices running on iOS,
Android and Windows Phone with a single API call
• Send Image/Text/URLs text-based Push Notifications
• Send messages in Channel Subscription Mode
• Send Scheduled Push as per Time-Zone
No infrastructure & scalability worries
Push Analytics
• Analyze your Push Campaign with App42 Analytics
• Evaluate the number of Push messages sent, delivered
and opened.
Why App42 Push Notification?
Creating a channel & scheduling
Push messages through AppHQ
A very useful feature that can track:
These analytics can be viewed from our AppHQ console.
Why Push Analytics?
When you use our Push Notification Service, each Push goes from the App42 server to
GCM/APNS/MPNS and then to the user device.
Thus, Analytics gives you a better insight of your Push Notification campaign.
Push Analytics
• Delivery of Push Notification is not guaranteed even from the service provider
• Once delivered, there might be a chance that user just clears it without opening the message
How many Push Notifications were sent from your side
How many were delivered, and
How many users opened the message
100%
74%
31%
Push Notification Campaign
Sent
Delivered
Opened
Integrating with iOS
First create a certificate from iOS Dev Center. (Visit tutorial: http://app42.sh/12dpgQW)
Install the.cer file, which was downloaded in the above step.
Convert the iPhone developer certificate into a .p12 file:
• Go to Applications/Utilities folder > Keychain Access application folder > Keys category
Select the private key associated with your iPhone Development Certificate (The private key is
identified by the iPhone Developer as: public certificate that is paired with it).
Select File > Export Items
Save your key in the (.p12) format.
You will be prompted to create a password which will be used when you will attempt to import this
key on another computer.
•
•
•
•
10 steps to PUSH
Now execute the following commands in the terminal:
Where,
- developer_identity.cer <= certificate you downloaded from Apple
- yourPrivateKey.p12 <= your private key
Make your .p12 file compatible with App42 server:
•
•
•
Contd..
Keep your .cer file and .p12 file in a single folder
Open terminal and go to the folder that has both the files.
1 openssl x509 -in developer_identity.cer -inform DER -out developer_identity.pem -outform PEM
2 openssl pkcs12 -nocerts -in yourPrivateKey.p12 -out yourPrivateKey.pem
3 openssl pkcs12 -export -inkey yourPrivateKey.pem -in developer_identity.pem -out iphone_dev.p12
shephertz-technologiess-iMac:~ shephertztechnologies$ cd "your folder path"
Upload iphone_dev.p12 file to the AppHQ console:
Open your Xcode project and navigate to the
AppDelegate.m class and change the
application:didFinishLaunchingWithOptions: method
to look like this:
The above code tells the OS that this App wants to receive push notifications.
Contd..
1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
2 {
3 // Let the device know we want to receive push notifications
4 [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
5 (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
6 return YES;
7 }
Add the following delegate methods in your AppDelegate.m in order to receive pushes:
When your App registers for remote (push) notifications, it tries to obtain a “device token”
(a 32-byte address of your device).
Contd..
1 - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
2 {
3 NSLog(@"My token is: %@", deviceToken);
4
5 // Prepare the Device Token for Registration (remove spaces and < >)
6 NSString *devToken = [[[[deviceToken description]
7 stringByReplacingOccurrencesOfString:@"<"withString:@""] stringBy ReplacingOccurrencesOfString:@">" withString:@""]
8 stringByReplacingOccurrencesOfString: @" " withString: @""];
9
10 NSLog(@"My Device token is: %@", devToken);
11 }
12
13 - (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
14 {
15 NSLog(@"Failed to get token, error: %@", error);
16 }
Now register your device with the App42 Server. Change the delegate method
application:didRegisterForRemoteNotificationsWithDeviceToken: in the AppDelegate.m class to look like this:
Contd..
1 - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
2 { NSLog(@"My token is: %@", deviceToken);
3 // Prepare the Device Token for Registration (remove spaces and < >)
4 NSString *devToken = [[[[deviceToken description]
5 stringByReplacingOccurrencesOfString:@"<"withString:@""] stringByReplacingOccurrencesOfString:@">" withString:@""]
6 stringByReplacingOccurrencesOfString: @" " withString: @""];
7 NSLog(@"My Device token is: %@", devToken);
8 /** * Register the device token for App42 Push notification services */
9 [self registerUserForPushNotificationToApp42Cloud:devToken]; }
10 -(void)registerUserForPushNotificationToApp42Cloud:(NSString*)deviceToken
11 { ServiceAPI *serviceObj = [[ServiceAPI alloc]init];
12 serviceObj.apiKey = APP42_APP_KEY;
13 serviceObj.secretKey = APP42_SECRET_KEY;
14 PushNotificationService *pushObj = [serviceObj buildPushService];
15 @try
16 { PushNotification *pushNotification =[pushObj registerDeviceToken:deviceToken withUser:@"User Name"];
17 [pushNotification release]; }
18 @catch (App42Exception *exception)
19 { NSLog(@"%@",exception.reason); }
20 @finally
21 { [serviceObj release];
22 [pushObj release]; } }
Now to send a Push Notification, call the following method in a commonly used class in your
project so that you can call this whenever you want to:
Contd..
1 -(void)sendPush:(NSString*)message
2 {
3 ServiceAPI *serviceObj = [[ServiceAPI alloc]init];
4 serviceObj.apiKey = APP42_APP_KEY;
5 serviceObj.secretKey = APP42_SECRET_KEY;
6 PushNotificationService *pushObj = [serviceObj buildPushService];
7 @try
8 { NSMutableDictionary *pushDictionary = [NSMutableDictionary dictionary];
9 [pushDictionary setObject:message forKey:@"alert"];
10 [pushDictionary setObject:@"default" forKey:@"sound"];
11 [pushDictionary setObject:@"1" forKey:@"badge"];
12 PushNotification *pushNotification = [pushObj sendPushMessageToUser:@"User Name" withMessageDictionary: pushDictionary];
13 [pushNotification release]; }
14 @catch (App42Exception *exception)
15 { NSLog(@"%@",exception.reason); }
16 @finally
17 { [serviceObj release];
18 [pushObj release]; }
19 }
The pushDictionary in the above code should always follow the same structure as mentioned
above to deliver the push notification successfully using App42 Server.
With the above mentioned step, your App has been successfully set up to receive/send Push
Notifications through our App42 Server using App42 Push Notification Service.
Contd..
You can remove or add the items to the pushDictionary if needed as per the Apple guidelines.
If you want to take any actions when you receive push notification then you need to add the
following delegate method in the AppDelegate.m class:
•
•
•
1 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
2 {
3 NSLog(@"%s..userInfo=%@",__FUNCTION__,userInfo);
4 /** * Dump your code here according to your requirement after receiving push */
5 }
IT IS THAT SIMPLE!!!
Some useful linksGetting Started:
Quick Start Guide
Sign-up for Free
Game Development Center
Concepts:
Backend as a Service
Massive Multiplayer Gaming Engine
App Analytics
Products:
App42 Cloud APIs - BaaS
AppWarp – Multiplayer Gaming Engine
AppHQ – Management Console
AppHawk – Project Management Tool
AppClay – Custom App Builder
Downloads:
App42 Cloud SDKs
App 42 Modules
Blogs:
Why BaaS?
Push Notification for iOS
Push Notification for Android
Real-time Multiplayer Games using Unity3D
Integrating Facebook in your Android App
Making a Turn-based Game
Using Query Interface
When to use NoSQL?
Add ‘Social’ to your Game
Links for Reference :http://www.shephertz.com
http://api.shephertz.com
http://appwarp.shephertz.com
http://app42paas.shephertz.com
Follow us on:
Contact: [email protected]
Skype: ShepHertz