Push Notifications Tutorial: Getting Started

More of these Jack! Important topic, easy for beginners, covers the fundamental components, easy to read!

Hi Jack,

Thanks for the great tutorial!
Can you please explain about the conversion between NSData to the token string?
What does the format ā€œ%02.2hhxā€ means?

Thanks!

Easier way is to integrate with push notification websites like

pushalive.com

This way you dont need any coding.

I think itā€™s not about iOS Push technology.

Hello Jack, we really appreciated the effort to bring us the knowledge, Im looking for the past tutorial write in objective -c to push notification, Could you provide us the url where we can find it please

Hi Jack,

Is it possible to still have access to the old Obj-C version of this article? I know swift is the drug of choice these days but my app is in obj-c, I got halfway through this article when it was in obj-c, and now I canā€™t find a cached version of it anywhere.

Thanks,
Rob

Jack,

Just want to say thank you for an excellent tutorial! A couple of hours saw me able to send notifications to an app on my iPad from a Raspberry Pi. I only hit one problem which took a little bit of searching to fix - first time round the option to save as .p12 in Keychain Assistant was inactive so I saved as .pem and skipped the OpenSSL step. However, that crashed and burned. Clicking on Certificates in Keychain Assistant before selecting the certificate for export activated the save as .p12 option and everything else was a walk in the park.

Thanks again for sharing your skill and helping starters like me ā€¦

Roy

You can store and validate according to the user . For example if you want some local notification only at particular weekdays or weekends . just see the below coding . Hope you understand from these .

-(void) weekEndNotificationOnWeekday: (int)weekday :(UILocalNotification )notification : (NSDate) alramDate
{
NSCalendar *calendar = [NSCalendar currentCalendar];

NSDateComponents *componentsForFireDate = [calendar components:(NSYearCalendarUnit | NSWeekCalendarUnit |  NSHourCalendarUnit | NSMinuteCalendarUnit| NSSecondCalendarUnit | NSWeekdayCalendarUnit) fromDate: alramDate];
[componentsForFireDate setWeekday: weekday] ; //for fixing Sunday

// [componentsForFireDate setHour: 20] ; //for fixing 8PM hour
// [componentsForFireDate setMinute:0] ;
// [componentsForFireDate setSecond:0] ;
notification.repeatInterval = NSWeekCalendarUnit;
notification.fireDate=[calendar dateFromComponents:componentsForFireDate];
[[UIApplication sharedApplication] scheduleLocalNotification:notification];

}

Hope these will be useful according to my knowledge .

Hi @vaibhavdev , I want to schedule a Local Notification when an app was in killed state. I am able to schedule it when the app was in foreground and background states. But, when app was in killed state unable to schedule it.
none of the delegate methods were called when app was killed.

Note: I am using silent notifications.

I am a newbie deveoper. What ports need to be open on my end to send push notifications? So far from what I understand it will need to be port 2195?? However, my client canā€™t open this port. Any way to get around this?

Hi Jack, Thank you so much for this tutorial. Following this managed to get the notifications in the development environment. But in production environment, not able to receive the notifications. Read somewhere that device tokens that works in the sandbox environment donā€™t work in the production env. not able to understand this. Can you help on this?

Hi Jack,

My application is VoIP application. If I use silent Push Notification then how long application will be woken up so that I can finish some task.For e.g. exchange of few messages from server

Hi jhtang,

Faced the same issue. Got the learnings listed below:

  1. The device token is different for development and production environments. So make sure you update your device token while testing on different environments.

  2. the APN urls are different for different environments
    ssl://gateway.sandbox.push.apple.com:2195
    ssl://gateway.push.apple.com:2195

  3. Make sure you are using proper certificates for different environments.

I hope it helps. :slight_smile:

Thank you very much for the tips. I realized that the device id could keep changing in either dev or prod environment. What i did is saving the device id in database. Since my app has the log in page, i even save the user id accompanied with the device id. So far everything works perfectly.

Hi Jack,
Could you show me how to change push notification pop-up?

My app say: ā€œMy Appā€ would like to send you notificatons?
Can i change it to: ā€œMy another Appā€ would like to send you notifications?

Thanks,

Thank you for tutorial Jack.
I notice I can use whatever passphrase to send the push notification using the PEM file. How come?
openssl pkcs12 -in WenderCastPush.p12 -out WenderCastPush.pem -nodes -clcerts

Another question: How do I determine the device token is for sandbox or production ?

I am not getting any notifications using above tutorials can anyone help me out in this?
This is really very irritatingā€¦
Plc help meā€¦

I have followed every steps explained in this tutorial starting from creating a certificate enabling push Notification and also creating the provisioning profile and exported the certificate to. p12 and also converted it to .pem running the commands and I have also put all the methods into Appdelegate and After running the app i get the device token which i have passed to the php file , when i run the php code and push a message, it shows Notification sent and Message Successfully Delivered but i am not getting any notification in my device

Iā€™ve been trying to do this on a Mac in Objective C, following your code and also looking at Appleā€™s PushyMac example. So far I havenā€™t seen the initial request come up to allow notifications. Any particular magic needed here?

Hi Jack

On the first picture in your article the computer is holding number two, presumably two push messages has been send to the app. But how do we control that the correct number is displayed. On our server we could handle it by getting a receipt from the app when a push mesage is read and then when next psuh message is send we update badge number accordingly. However I would prefer a more simple solution where the device OS takes care of this by letting our server send something like: badgenumber=+1. Is this second and more simple solution possible?