jump to navigation

Apple Push Notification Service Tutorial July 31, 2009

Posted by Ameya in iPhone, iPhone App Devlopment.
Tags: ,
trackback

Apple Push Notification Service (APNS) an service user by apple to notify application. The notification can be of various Text Alert with or without sound, Baggage number update on icon etc.

Below are the steps to construct an simple application that receives notification form APNS.

The steps are for development testing on sandbox APNS service from Apple

Getting Ready with Certificate and key.

  1. Generate a certificate signing request from your Mac’s keychain and save to disk.(Steps same as creating certificate for development but don’t submit not).Pleas store this certificate in a safe location as it might be re-required to invoke APNS.
  2. Login into your development account and visit iPhone Developer Program Portal.
  3. Click App IDs on left. Create an new id without wild charter (com.mydomain.applicationName). This name will be used while setting up your application to be signed with development certificate. If you use wild character like ‘*’ the iPhone Developer Program Portal will not allow the App ID to be used for notification.
  4. After submitting the new App ID you will be guided to the list page. Click configure to edit setting. Check ‘Enable for Apple Push Notification service’ to enable APNS , and click Configure next to ‘Development Push SSL Certificate’.
  5. Upload your request certificate generated in step 1 and download the certificate (aps_developer_identity.cer) from the Program Portal. Double click on this certificate to save it your key chain. Export this key by clicking on this newly installed certificate. The exported key is saved as Certificate.p12 file on your system. Please store it other files uploaded or downloaded from portal program. This .p12 file is used in later steps for signing your Provider server.
  6. Click on Provisioning in left bar and create a new provisioning profile. Use the new created App Id and select the device you want to use for development. Download the new provisioning profile save with other files. Close XCode if open and drag drop new provisioning profile on your XCode in your Doc bar.Your ready with certificate and key.

Getting ready with the application

  • Create an simple view based application.
  • Paste these line of code in your application.

- (void)applicationDidFinishLaunching:(UIApplication *)app {
// other setup tasks here….
[window addSubview:viewController.view];
[self alertNotice:@"" withMSG:@"Initiating Remote Noticationss Are Active" cancleButtonTitle:@"Ok" otherButtonTitle:@""];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound)];
}

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
//NSLog(@”devToken=%@”,deviceToken);
[self alertNotice:@”” withMSG:[NSString stringWithFormat:@"devToken=%@",deviceToken] cancleButtonTitle:@”Ok” otherButtonTitle:@””];
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
NSLog(@”Error in registration. Error: %@”, err);
[self alertNotice:@”” withMSG:[NSString stringWithFormat:@"Error in registration. Error: %@", err] cancleButtonTitle:@”Ok” otherButtonTitle:@””];
}

-(void)alertNotice:(NSString *)title withMSG:(NSString *)msg cancleButtonTitle:(NSString *)cancleTitle otherButtonTitle:(NSString *)otherTitle{
UIAlertView *alert;
if([otherTitle isEqualToString:@""])

alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:cancleTitle otherButtonTitles:nil,nil];
else
alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:cancleTitle otherButtonTitles:otherTitle,nil];
[alert show];
[alert release];
}

  1. Please be careful with the error reporting part in the code as error tell a lot about the development state.
  2. Right click on the application in target in the left and click Get Info to configure the application. Click on property tab and paste your App ID in the identifier text-field.
  3. Click build tab, select debug and select your new provisioning profile.
  4. Click Device 3.0 and Build Go to distribute binary to your connected device.
  5. Starting the application it should first alert and message that it registering for notification. Followed by and alert the application is registering for notification allow or deny. Followed by an alert that displays the device token ID. Note this token as this will be used by your server code to communicate with your device. If the second message is error then either something has gone wrong with the certificate and your application cannot register your certificate start over again.

Getting ready with Notification service provider.
Download an stand alone MAC application (PushMeBaby http://stefan.hafeneger.name/download/PushMeBabySource.zip) to test. There are two modification in the application to get started.
Place an copy of the aps_developer_identity.p12 file in the application folder. Import the file in the application by right clicking and Add > Existing File.
Set the following in the application’s delegate file as shown below

self.deviceToken = @”XXXXX XXXXX XXXXX XXXXXX XXXXXX”;
//First your device id token.
self.payload = @”{\”aps\” : { \”alert\” : \”You got your emails.\”,\”badge\” : 9,\”sound\” : \”bingbong.aiff\”},\”acme1\” : \”bar\”,\”acme2\” : 42}”;
//The pay load
self.certificate = [[NSBundle mainBundle] pathForResource:@”aps_developer_identity” ofType:@”cer”]; //The certificate file.

  • Don’t depend on the application’s text-field as it doesn’t work.
  • Start the application and you will get a message the application is trying to access your key , click ‘Allow’. Click Push in the application window. Wait for a 20 seconds and you should immediately get an notification on your iPhone / iTouch.

Getting ready with test code for actual provider sever (PHP).

  • For server on linux environment you will require different kind of certificate. Following are the steps to create it. Use MAC console to fire the following commands.

openssl pkcs12 -clcerts -nokeys -out cert.pem -in Certificate.p12
provide new password if asked.
openssl pkcs12 -nocerts -out key.pem -in Certificate.p12
provide new password if asked.
cat cert.pem key.unencrypted.pem > ck.pem

Create an PHP file provide.php

$message);
if ($badge)
$body['aps']['badge'] = $badge;
if ($sound)
$body['aps']['sound'] = $sound;
/* End of Configurable Items */
$ctx = stream_context_create();
stream_context_set_option($ctx, ‘ssl’, ‘local_cert’, ‘ck.pem’);
// assume the private key passphase was removed.
// stream_context_set_option($ctx, ‘ssl’, ‘passphrase’, $pass);
$fp = stream_socket_client(‘ssl://gateway.sandbox.push.apple.com:2195′, $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
if (!$fp) {
print “Failed to connect $err $errstrn”;
return;
}
else {
print “Connection OKn”;
}
$payload = json_encode($body);
$msg = chr(0) . pack(“n”,32) . pack(‘H*’, str_replace(‘ ‘, ”, $deviceToken)) . pack(“n”,strlen($payload)) . $payload;
print “sending message :” . $payload . “n”;
fwrite($fp, $msg);
fclose($fp);
?>

Note : Your PHP server must have json_encode support.

Run your file on linux console as ‘php provide.php’

For more information refer http://www.macoscoders.com/2009/05/17/iphone-apple-push-notification-service-apns/

_____________________________________________________________________________________________________________________

There is an open source PHP/MySQL back-end for APNS. So if you want your own integration of push notifications on your own server, here you go :)
Main Link: http://www.easyapns.com
Google Code: http://code.google.com/p/easyapns/
Google Group: http://groups.google.com/group/easyapns
contributed by [mrmidi] manifestinteractive@gmail.com

_____________________________________________________________________________________________________________________
About these ads

Comments»

1. pramod - August 12, 2009

I would like to know whether only one development cert is enough for an application with different versions having APNS enabled and disabled.

Ameya - August 12, 2009

Yes , only one development cert is enough for an application with different versions having APNS enabled and disabled. But note that certificate should be developed using steps in “Getting Ready with Certificate and key” also the certificates have one to one mapping i.e one developer certificate goes with one application. Also note not to mix developer and distribution certificates as these are certificates are for communication two different APNS servers that is sandbox APNS for development and distribution APNS for distribution.

pramod - August 12, 2009

Hi,

Thanks for the reply.

I had some more doubts.

1) In the document, it was said to install the certificate downloaded on the provider server.
Can u tell me how to do this?

2) Also what does the parameter ‘local_cert’ implies in stream_context_set_option [stream_context_set_option($ctx, ’ssl’, ‘local_cert’, ‘ck.pem’); ]
If we want to do it for production environment, wht is the paremeter we have to place.

Thank you.

2. pramod - August 12, 2009

chr(0) . pack(”n”,32) . pack(’H*’, str_replace(’ ‘, ”, $deviceToken)) . pack(”n”,strlen($payload)) . $payload;

What does it specifies?

3. Ameya - August 12, 2009

I am not a php expert and I may be wrong, but can tell by seeing the out put that the mgs = devicetoken(encrypted) + payload .

pramod - August 12, 2009

Thanks. for the reply.

4. pramod - August 12, 2009

Hi I also like to know what is the role of Device token in the APNS Implementation. Why it is required for APNS Implementation

5. Ameya - August 12, 2009

The device token is shared key (or common entity ) in the whole communication process , helps to identify each device uniquely and what has to be sent to that device. The actual process is ,
1) Registering device token. If you expand this process, the device sends a request to register to APNS server , the APNS responds with device token. You should use this device token for future communication and the device token uniquely identifies that device only. So you should send the device token to provider server and try to map the device token with the user credentials , as the information to be sent to one user will be different from other users.
2) APNS send message to the device. The message can be alert msg, icon number update or sound alert to user and may vary from user to user. This step consists of first the provider communicating with the APNS using device token (this tells APNS that I have some alert for a particular device and the msg is as follows). The APNS will use device token to search for device and communicate with it using carrier(iPhone) or WIFI (internet).

pramod - August 12, 2009

Hi ,

Thaks for the useful info.
I am little bit confused. How the provider can know the device token of its users? Is there programming reqd behind this.

Thank u.

6. Ameya - August 12, 2009

Yes there will be some extra code in this method “-(void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken” that will send the device token in the header of request to device token also send some additional info like user id if there is login involved in the application so the provider can associate this device token with login id. If your application does not involve any users account then simply continue collecting device token , and when a alert is generated simply send using the php code to all device token registered with your provider.

pramod - August 12, 2009

Hi,

Thanks for the great help you have been doing.

It means we have to write POST Method for sending the devicetoken back to the provider.

Do this method should run every time the user starts the application, or its enough when user installs the application for the first time.

As I am going to the documents I have been getting much doubts.

One more thing I had is , what is the Feedback service provided by apple for APNS. How it can be used.

Thank u.

7. pramod - August 12, 2009

Does APNS Works on the UNLOCKED and JAILBREAK iphones.

Ameya - August 12, 2009

I am not sure about that, as I have an iPod Touch for testing and that does not require jail breaking. I feel that it may not work as your are removing the security put by apple for it to work with patent carriers. I also feel it might work as your only removing the security for not enabling other sim to be used on iPhone devices except the one which apple agrees on.

The person who has posted on SDK forum might not have got APNS in the right manner and in a panic is asking weather it works on jail broken SDK.

8. Extenze - August 19, 2009

I just love your weblog! Very nice post! Still you can do many things to improve it.

9. buyvigrx - September 12, 2009

I think your blog need a new wordpress template. Downalod it from http://templates.wordpressguru.in, The site has nice and unique wordpress templates.

10. Adeem Basraa - September 18, 2009

ok i have one question for you, i m testing application from my mac and it works fine but when i put this php code on server it gives me an error of
“Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection refused) in /home/content/14/4875914/html/code/push/apns.php on line 15
Failed to connect 111 Connection refused ”

any idea?

11. Ameya - September 18, 2009

Is your SSL certificate generated by apple integrated into the php application properly, double check your URL string for connection. I will try to post a simple tutorial for PHP APNS server.

12. Adeem Basraa - September 19, 2009

i have try again, but the issue might be that im using godaddy.com as a server and it didnt open that port for ssl? What server you try to use this push system?
Do you think its a webhosting problem or its the way i m working on?

Bcoz things work fine when i put the php in our mac server and it shows me the alert. Thank you for your help!

13. Youssef Henry - September 26, 2009

i have this warning on the php
Warning: stream_socket_client() [function.stream-socket-client]: Unable to set local cert chain file `/Users/dennet/Sites/APNS/ck.pem’; Check that your cafile/capath settings include details of your certificate and its issuer in /Users/dennet/Sites/APNS/ssl.php on line 25

any one can help i doubled checked the creation process of the certificate.
my server is linux should i create the certificates file using linux? if yes how?

14. Youssef Henry - September 26, 2009

i fixed it but the alert and the sound work and the badge doesn’t work. any one can help.
the fix is to easy i just copy the private key and the certificate to the server and convert them to pem on the server not on my machine.

15. Gangadhar - October 6, 2009

Hai ,
I tried the way you mentioned in the blog. The application was successfully installed in the mobile . I got the first message but I did not get the second message regarding the device token. Can you say me any changes that I have to make in the process. some informtion like the domain name etc.,

Ameya - October 7, 2009

Are printing or logging error , you might get a clue of what went wrong. I had also landed up in this frustrating situation of doing everything corretly yet not reciving any device token. Also check this statemet is ok [self alertNotice:@”” withMSG:[NSString stringWithFormat:@"devToken=%@",deviceToken] cancleButtonTitle:@”Ok” otherButtonTitle:@””]; which will print the device token. Best of luck !

Gangadhar - October 21, 2009

Hai ,
The problem was solved when my client upgraded his mobile to the latest version. But I have one more dobut as there was a contradiction between the statements in the tutorial
“Place an copy of the aps_developer_identity.p12 file in the application folder” and ”pathForResource:@”aps_developer_identity” ofType:@”cer”]; //The certificate file.”
In the first statement you asked to place the .p12 file but in the next statement you mentioned .cer file. Can you be clear on this .

Thanks in advance,

Gangadhar - October 21, 2009

Hai ,
I just checked out placing both .pl12 and .cer files. If i place the .p12 files it is showing error . So I replaced it with .cer file. Then I got a successful result. I mean the result in the below statement from PUSHMEBABY gave me “” Call succeeded with no error”.
“OSStatus result = SSLWrite(context, &message, (pointer – message), &processed);”

But the mobile is not receiving any messages. Is there something I have to do more from mobile part. The mobile is updated to the latest version . Is there a chance that outgoing port 5223 for fire wall for my WiFi AP has been blocked. Any suggestions are accepted.

Thanks in advance,

16. vviji - October 7, 2009

Hi,
Neither the didFailToRegisterForRemoteNotificationsWithError nor the didRegisterForRemoteNotificationsWithDeviceToken methods are invoked in my app. Is there any way to debug this issue?

I am using WiFi connection on iPhone 3G the app was developed using XCode 3.1
Thanks for your help.

Ameya - October 7, 2009

The connection and sdk should not be an issue, are you using an iphone that is jaibroken ? (as I dont know how it work on that.) I use an Itouch , where you can simulate most of the thing. Also remember that you need to test this with real device like iphone any G / iTouch with 3.+ OS updated.

Q) Neither the didFailToRegisterForRemoteNotificationsWithError nor the didRegisterForRemoteNotificationsWithDeviceToken methods are invoked in my app. Is there any way to debug this issue?

A) Are you putting a pop up message as i have mentioned. This will help you debugginh in devices.

vviji - October 8, 2009

Thanks for the reply.
I am using an iPhone 3G with 3.0.1(7A400) OS. The device is not unlocked or jailbroken.

Q) Are you putting a pop up message as i have mentioned. This will help you debugginh in devices.
A} Yes, I have added the popup messages and the NSLogs. Both do not appear.

Thanks for your help.

Ameya - October 8, 2009

Run your application on device, hooked up to the sdk and run debugger to check the values of the varible.

vviji - October 8, 2009

Thanks again.
Is there any specific variable which could be useful? Are you referring to the deviceToken parameter?

Ameya - October 8, 2009

You can check the flow the put break point for each deligate method, and see if they are called.

vviji - October 8, 2009

I tried putting brkpoints in the delegates but found that none of the delegates were called.

Thanks for your patience.

Ameya - October 8, 2009

The deligate method should be called implicitly, as it in UIApplicationDelegate

if it is not woring implicitly, try calling it explicitly, in your header file. Also tell me what deligate ur currently calling ?

17. vviji - October 8, 2009

I checked & found that the applicationDidFinishLaunching() is called. In the iPhone simulator the didFailToRegisterForRemoteNotificationsWithError is called.
Does it answer your query?

Should I call the didRegisterForRemoteNotificationsWithDeviceToken explicitly?

Ameya - October 8, 2009

You should not check notification applications in simulator at all, it never works there always check in device, connect device to mac change option to device and debug and start the application. The application should start running on ur device, and u can put break point in your code and check what is called and what not.

18. vviji - October 9, 2009

FOUND SOLUTION
The outgoing port 5223 for fire wall for my WiFi AP had to be opened.
Refer –

https://devforums.apple.com/thread/25656?tstart=0

Ameya - October 9, 2009

Thank you, for bringing down you problem on comment, may be this will help some other devloper who has similar problem.

Gangadhar - October 27, 2009

Hai ,
.Please let me know whether gettting of device token is independent of opening the port 5223.

Thanks and regards,

19. rahulvyas - October 12, 2009

self.deviceToken = @”XXXXX XXXXX XXXXX XXXXXX XXXXXX”;
self.payload
self.certificate

you haven’t mentioned type of these variables.

Ameya - October 12, 2009

you can ues an NSString type variable.

this is the main part

– (void)applicationDidFinishLaunching:(UIApplication *)app {

// other setup tasks here….

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];

}

// Delegation methods

– (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {

const void *devTokenBytes = [devToken bytes];

self.registered = YES;

[self sendProviderDeviceToken:devTokenBytes]; // custom method

}

– (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {

NSLog(@”Error in registration. Error: %@”, err);

}

Apple doc for push notification

20. hardik - October 21, 2009

hi,
as an developer theses are the steps ,but as an iphone user i don’t do all these procedure then how will it be done?
user only clicks yes on notification and he gets notification

21. Unknown - October 24, 2009

After Running Project my project show following warning. Do you tell me why it show this?

warning: Unable to read symbols for “”/Users/riseuP/Desktop/iPhone Project/PushTest/build/Debug-iphoneos”/PushTest.app/PushTest” (file not found).
warning: Unable to read symbols for “”/Users/riseuP/Desktop/iPhone Project/PushTest/build/Debug-iphoneos”/PushTest.app/PushTest” (file not found).
warning: Unable to read symbols for “/Library/MobileSubstrate/MobileSubstrate.dylib” (file not found).
2009-10-25 09:27:33.190 PushTest[2758:207] MS:Notice: Installing: com.riseuplabs.mas (478.470000)
2009-10-25 09:27:33.599 PushTest[2758:207] MS:Notice: Loading: /Library/MobileSubstrate/DynamicLibraries/WinterBoard.dylib
warning: Unable to read symbols for “/Library/MobileSubstrate/DynamicLibraries/WinterBoard.dylib” (file not found).
2009-10-25 09:27:34.287 PushTest[2758:207] WB:Notice: WinterBoard

22. faisal - October 25, 2009

Hi, a nice tutorial.
Here I have learned a lot.
But I m getting following problem:
I can not find device token.
the following delegate methods do not invoked.
1. (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
2.- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err

please help me!

23. Reseller Hosting - January 8, 2010

Your blog keeps getting better and better! Your older articles are not as good as newer ones you have a lot more creativity and originality now keep it up!

24. Stuart Buchbinder - January 29, 2010

I followed the tutorial and everything seemed to be working fine until I clicked ‘Don’t Allow’. Once I did that and everytime I run it from then on, didRegisterForRemoteNotificationsWithDeviceToken doesn’t get called and neither does didFailToRegisterForRemoteNotificationsWithError.

It works fine in the editor (spitting back an error) but when I build to device…nothing. My appID and provisioning profile are set up correctly as this worked the first time.

Any ideas?

Ameya - January 30, 2010

Can you check your setting on the device , there is an UI for alerts and notification , try turning it on from there.

25. kalyan - April 1, 2010

Hello ,

I have followed the each and every step and my mobile has registered successfully for Push Notification Service and returned the device token.

I have used the PushMeBaby app for Pushing the message. I have included the aps_developer_identity.cer in the application and included the Device token (Ex: 40e4145d ee723afb xxxxxxx…..).

But I did not get any notification on iPhone??

Is we need to remove the spaces in Device Token OR is any thing need to configure ??

ram - April 1, 2010

Do we need to include the aps_developer_identity.p12 or aps_developer_identity.cer in the application folder??

As in the code is file type is mentioned .cer but in the explanation mentioned aps_developer_identity.p12 to be in the app folder !!

Gangadhar - April 19, 2010

I am even suffering with the same problem. So please let me know if you found an solution.

Ameya - April 19, 2010

@Gangadhar can please elaborate your problem , like where your getting the error , in the APNS server part or the client ,

Gangadhar - April 19, 2010

Hi Ameya,
Thanks for your immediate response. I have got the device token for the apns application . Then with that device token I have sent a message using Push Me Baby. Yet I did not receive any notification. I was stuck with this APNS problem for the past 2 months. If you want the code I will send you for verification. Do I have to free any other port on the network
Thanks in advance

26. Ameya - April 17, 2010

Hay Guys ,

Pleas re comment for new problem , was working on some heavy JAVA project , I am back to answer questions.

27. SeanChang - May 12, 2010

This sample lost something that is receive message code;

example:

– (void) showString: (NSString *) aString
{
UITextView *tv = (UITextView *)[[[UIApplication sharedApplication] keyWindow] viewWithTag:TEXTVIEWTAG];
tv.text = aString;
}

// Handle an actual notification
– (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSString *status = [NSString stringWithFormat:@”Notification received:\n%@”,[userInfo description]];
[self showString:status];
//[self alertNotice:@”” withMSG:[NSString stringWithFormat:@”%@”, [userInfo description]] cancleButtonTitle:@”Ok” otherButtonTitle:@””];
NSLog(@”jsonStr before%@”,[userInfo description]);

//sample json code
// NSString *jsonString = @”{\”aps\”:{\”alert\”:\”I Love You\”,\”badge\”:1}}”;

NSString *jsonString = @””;

if ([userInfo description]!=nil) {
jsonString=[userInfo description];
jsonString = [jsonString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
}
NSLog(@”jsonStr%@”,jsonString);
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF32BigEndianStringEncoding];
NSDictionary *dictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:nil];

NSDictionary *tweetsObj = [dictionary objectForKey:@"aps"];
NSString *alert_message=@””;
//NSLog(@”is %@”,[tweetsObj objectForKey:@"alert"]);
if(tweetsObj==nil){
alert_message=@”Push Message is null”;
}else{
alert_message=[tweetsObj objectForKey:@"alert"];
}
[self alertNotice:@”” withMSG:[NSString stringWithFormat:@"%@", alert_message] cancleButtonTitle:@”Ok” otherButtonTitle:@””];
}

// Report the notification payload when launched by alert
– (void) launchNotification: (NSNotification *) notification
{
[self performSelector:@selector(showString:) withObject:[[notification userInfo] description] afterDelay:1.0f];
}

28. Sekhar - June 4, 2010

Can you please suggest me, Where should I place the following code.

self.deviceToken = @”XXXXX XXXXX XXXXX XXXXXX XXXXXX”;
//First your device id token.
self.payload = @”{\”aps\” : { \”alert\” : \”You got your emails.\”,\”badge\” : 9,\”sound\” : \”bingbong.aiff\”},\”acme1\” : \”bar\”,\”acme2\” : 42}”;
//The pay load
self.certificate = [[NSBundle mainBundle] pathForResource:@”aps_developer_identity” ofType:@”cer”]; //The certificate file.

Lepidopteron - August 4, 2010

In ApplicationDelegate.m

Line 26 – Line 32

Just replace the old ones.

So it will look like:

———————————-
#pragma mark Allocation

– (id)init {
self = [super init];
if(self != nil) {
self.deviceToken = @”XXXXX XXXXX XXXXX XXXXXX XXXXXX”;
//First your device id token.
self.payload = @”{\”aps\” : { \”alert\” : \”You got your emails.\”,\”badge\” : 9,\”sound\” : \”bingbong.aiff\”},\”acme1\” : \”bar\”,\”acme2\” : 42}”;
//The pay load
self.certificate = [[NSBundle mainBundle] pathForResource:@”aps_developer_identity” ofType:@”cer”]; //The certificate file.
}
return self;
}
———————————-

29. Apple Push Notification Resources « Brainwash Inc. – iPhone/Mobile Development - September 8, 2010

[...] Notification Resources Here are some great tutorials/examples/etc. about APN: Boxed Ice iPhone App Dev Help [...]

30. shyam - November 8, 2010

I am a PHP developer.
while using the below code i am getting message “Failed to connect 0″. Please help me to fix this.

$ctx = stream_context_create();
stream_context_set_option($ctx, ‘ssl’, ‘local_cert’, ‘apns-dev.pem’);
// assume the private key passphase was removed.
// stream_context_set_option($ctx, ‘ssl’, ‘passphrase’, $pass);

$fp = stream_socket_client(‘ssl://gateway.sandbox.push.apple.com:2195′, $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
if (!$fp) {
print “Failed to connect $err $errstrn”;
return;
}
else {
print “Connection OKn”;
}

Thanks in advance,
Shyam

31. links for 2010-11-09 | Alones world - November 9, 2010

[...] Apple Push Notification Service Tutorial « iPhone App Dev Help registerForRemoteNotificationTypes (tags: pns) [...]

32. 2010 in review « iPhone App Dev Help - January 3, 2011

[...] The busiest day of the year was September 28th with 159 views. The most popular post that day was Apple Push Notification Service Tutorial. [...]

33. APNS PHP Server » 918 Dev - January 9, 2011

[...] A different Apple Push Notification Service Tutorial [...]

parminder - January 19, 2012

which one are you talking about

34. Muhammad Ali - January 28, 2011

Hi I am getting this error

Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.push.apple.com:2195 (Connection refused) in /home/wiztech/public_html/apns1/Push1.php on line 13
Error: Connection refused (111)
Warning: fwrite(): supplied argument is not a valid stream resource in /home/wiztech/public_html/apns1/Push1.php on line 22

Warning: socket_close() expects parameter 1 to be resource, boolean given in /home/wiztech/public_html/apns1/Push1.php on line 25

Warning: fclose(): supplied argument is not a valid stream resource in /home/wiztech/public_html/apns1/Push1.php on line 26

Please help

35. iphone create a .pem file for windows server - iPhone Dev SDK Forum - February 2, 2011

[...] iphone create a .pem file for windows server I followed the link below. here he has told how to create a .pem file for libux server. Can anyone tell me how to create a .pem certificate for windows server? Apple Push Notification Service Tutorial iPhone App Dev Help [...]

36. roshni - September 2, 2011

hi,
I used your PushMeBaby server and push app with my certificate and provisioning profile,it gave notification in form of alert on device and print the statement on console written in method only when first time I ran the application,but while running the application for next multiple times for testing it returns only device token,the following method doesnt execute at all.Please help me solving this problem.
– (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

for (id key in userInfo) {
NSLog(@”key: %@, value: %@”, key, [userInfo objectForKey:key]);

UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@”alert” message:key delegate:self cancelButtonTitle:@”ok” otherButtonTitles:nil];
[alert show];

/*if(key)
{

UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@”alert” message:@”this is in application” delegate:self cancelButtonTitle:@”ok” otherButtonTitles:nil];
[alert show];
}*/

}

}

37. Paul - November 2, 2011

Hello, thanks for the tuto. Two questions:
– How much push messages are allowed?? or is not limit for it?? And the max number tokens for open socket??
– Which have better performance for a lot of push, the sandbox of the production environments??

Tahnks a lot

38. parminder - January 19, 2012

This is a great tutorial but can anybody tell me how to get the device token. do i need to plug in my iphone or ipod or ipad or at which point it is goona recognize my device token. thanks in advance

39. chings228 - February 7, 2012

NotingMe.com provides a web interface and HTTP api to do push notification if NotingMe App is installed in IOS devices

for more detail, please visit http://www.NotingMe.com

40. pożyczki pozabankowe - May 1, 2013

I think this is among the most important information for me.
And i’m glad reading your article. But should remark on some general things, The web site style is perfect, the articles is really great : D. Good job, cheers


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 25 other followers

%d bloggers like this: