<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Discussion Delegate &#187; code</title>
	<atom:link href="http://vxtindia.com/blog/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://vxtindia.com/blog</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Fri, 23 Jul 2010 08:53:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Push Notifications in your iPhone App using PHP and Ubuntu</title>
		<link>http://vxtindia.com/blog/push-notifications-for-your-iphone-app-with-php-and-ubuntu/</link>
		<comments>http://vxtindia.com/blog/push-notifications-for-your-iphone-app-with-php-and-ubuntu/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 13:43:26 +0000</pubDate>
		<dc:creator>Sudhanshu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apns]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[push notifications]]></category>

		<guid isPermaLink="false">http://vxtindia.com/blog/?p=99</guid>
		<description><![CDATA[Push Notifications have been around for quite some time now, but when we started on it, we found out that we were unable to find all the information about creating a demo in one place. After a few hours, we were able to get it to work. Here is what we did.
Basically, the code on [...]]]></description>
			<content:encoded><![CDATA[<p>Push Notifications have been around for quite some time now, but when we started on it, we found out that we were unable to find all the information about creating a demo in one place. After a few hours, we were able to get it to work. Here is what we did.</p>
<p>Basically, the code on your server needs to talk to the <u>Apple Push Notification Service (APNS)</u> to send the messages, and the APNS then delivers them to your phone. <u>We will only provide the code level details</u> here to help you carry out the same on your server.</p>
<h2>Basic Idea</h2>
<p>You need to do the following to get your application to send push notifications</p>
<blockquote><p>1. Make your application accept Push Notifications<br />
2. Create a SSL certificate for your server which will allow it to talk to the APNS<br />
3. Create the payload for each message to be send to the APNS<br />
4. Send all the payloads one by one to the APNS
</p></blockquote>
<p>Even if you have already been into iPhone development for sometime, you might not be aware of the <strong>&#8216;DevToken&#8217;</strong>. This is a <em>uniquely generated token</em> for your iPhone application on a particular phone. It can keep changing over time for a particular phone as well, but it is the unique id that will help you send a message to a particular application on a particular phone.</p>
<p>This is what it looks like on our phone</p>
<blockquote><p>4d3d32e4 c1beebd2 f3a6bc85 3f7d12b9 abc156b4 26818ecf 9673a712 85e01adc</p></blockquote>
<p>This is what you need to do to get your device token.</p>
<p><script src="http://gist.github.com/390635.js"></script></p>
<h2>Getting the certificates in place</h2>
<p>Reach for your mac and start doing the following</p>
<p>1. Login to the <a href="http://developer.apple.com/iphone/manage/overview/index.action">iPhone Developer Connection Portal</a> and click on <em>App Ids</em>.</p>
<p>2. Create an AppId for your application witouth a wildcard. It should be something like this : </p>
<blockquote><p>com.vxtindia.PushSample</p></blockquote>
<p>3. Click configure and then go ahead and create a <em>certificate for Push Notifications</em>.<sup>[<a href='#reference1'>1</a>]</sup>. Download it once it has been created.</p>
<p>4. Import the newly created certificate into your keychain by double clicking it.</p>
<p>5. Launch <em><strong>&#8216;Keychain Assistant&#8217;</strong></em> and filter it by the Certificate&#8217;s category. There you should see a <strong><em>&#8216;Apple Development Push Services&#8217;</em></strong> option. Expand it, right click on it and click on &#8216;Export &#8230;&#8217; and save this as apns-dev-cert.p12 . Also download the private key as <em>apns-dev-key.p12</em></p>
<p>6. Copy the file <em>apns-dev-cert.p12</em> to your server in the folder where you will put the rest of your PHP code.</p>
<p>7. Now run the following code on the server<br />
<code>openssl pkcs12 -clcerts -nokeys -out apns-dev-cert.pem -in apns-dev-cert.p12<br />
openssl pkcs12 -nocerts -out apns-dev-key.pem -in apns-dev-key.p12<br />
</code></p>
<p>We are running everything from a server running <em>Ubuntu-9.04</em>. Here we had to remove the passphrase, which can be done as follows<br />
<code>openssl rsa -in apns-dev-key.pem -out apns-dev-key-noenc.pem</code></p>
<p>Finally, combine the two to get your apns-dev.pem file<br />
<code>cat apns-dev-cert.pem apns-dev-key-noenc.pem > apns-dev.pem</code></p>
<p>8. You need to create a payload and send it to the APNS server. You can use the following code to do so<br />
<script src="http://gist.github.com/390637.js"></script></p>
<p>9. Great work! You have just pushed a message to the APNS which will now be delivered to a phone running your application.</p>
<p>10. <strong>(Optional)</strong> Apple also provides a Feedback service (which doesn&#8217;t do anything that you would expect). This service tells you when was the last time that APNS failed to find your application on a specific phone. When this happens, you need to stop sending updates to that Device Token.</p>
<p>To assist you in your endeavors, here is the code to help you read this data<br />
<script src="http://gist.github.com/390641.js"></script></p>
<p>That&#8217;s it. You are now officially a pro at push notifications!</p>
<p>References :<br />
1. <a name='reference1' href="http://developer.apple.com/iphone/prerelease/library/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ProvisioningDevelopment/ProvisioningDevelopment.html#//apple_ref/doc/uid/TP40008194-CH104-SW4">Apple&#8217;s Documentation</a><br />
2. <a rel="nofollow" href="http://blog.boxedice.com/2009/07/10/how-to-build-an-apple-push-notification-provider-server-tutorial/">BoxedIce</a></p>
<img src="http://vxtindia.com/blog/?ak_action=api_record_view&id=99&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://vxtindia.com/blog/push-notifications-for-your-iphone-app-with-php-and-ubuntu/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- This site's performance optimized by W3 Total Cache. Dramatically improve the speed and reliability of your blog!

Learn more about our WordPress Plugins: http://www.w3-edge.com/wordpress-plugins/


Served from: vxtindia @ 2010-09-10 18:43:35 -->