<?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 Lazy Sys Admin&#187; Programming</title>
	<atom:link href="http://www.thelazysysadmin.net/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thelazysysadmin.net</link>
	<description>Why do things the hard way?</description>
	<lastBuildDate>Mon, 07 Jun 2010 22:24:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>APNS error &#8211; No Valid aps-environment entitlement</title>
		<link>http://www.thelazysysadmin.net/2009/07/apns-error-no-valid-aps-environment-entitlement/</link>
		<comments>http://www.thelazysysadmin.net/2009/07/apns-error-no-valid-aps-environment-entitlement/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 11:33:29 +0000</pubDate>
		<dc:creator>Jon Smith</dc:creator>
				<category><![CDATA[Objective C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[APNS]]></category>

		<guid isPermaLink="false">http://www.thelazysysadmin.net/?p=555</guid>
		<description><![CDATA[If you get the following error when trying to register for a device token, firstly ensure you have correctly followed the directions within the iPhone Developers Portal. Error Domain=NSCocoaErrorDomain &#34;no valid 'aps-environment' entitlement string found for application&#34; If after you have verified your Provisioning Profile and application settings you still get the error, try the [...]]]></description>
			<content:encoded><![CDATA[<p>If you get the following error when trying to register for a device token, firstly ensure you have correctly followed the directions within the iPhone Developers Portal.</p>
<pre class="brush: plain;">
Error Domain=NSCocoaErrorDomain &quot;no valid 'aps-environment' entitlement string found for application&quot;
</pre>
<p><span id="more-555"></span>If after you have verified your Provisioning Profile and application settings you still get the error, try the following:</p>
<p>Go to the Project Settings in the Project Menu</p>
<p><a href="http://www.thelazysysadmin.net/wp-content/uploads/2009/07/APNS-Error-1.png"><img class="alignnone size-full wp-image-559" title="APNS Error 1" src="http://www.thelazysysadmin.net/wp-content/uploads/2009/07/APNS-Error-1.png" alt="APNS Error 1" width="600" height="400" /></a></p>
<p>Select the exact Code Signing identity for your application rather then the automatic selection.</p>
<p><a href="http://www.thelazysysadmin.net/wp-content/uploads/2009/07/APNS-Error-2.png"><img class="alignnone size-full wp-image-560" title="APNS Error 2" src="http://www.thelazysysadmin.net/wp-content/uploads/2009/07/APNS-Error-2.png" alt="APNS Error 2" width="600" height="536" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thelazysysadmin.net/2009/07/apns-error-no-valid-aps-environment-entitlement/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>APNS Send Device Token to Provider</title>
		<link>http://www.thelazysysadmin.net/2009/07/apns-send-device-token-to-provider/</link>
		<comments>http://www.thelazysysadmin.net/2009/07/apns-send-device-token-to-provider/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 05:38:37 +0000</pubDate>
		<dc:creator>Jon Smith</dc:creator>
				<category><![CDATA[Objective C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[APNS]]></category>
		<category><![CDATA[Obj-C]]></category>

		<guid isPermaLink="false">http://www.thelazysysadmin.net/?p=493</guid>
		<description><![CDATA[I am currently in the middle of designing and developing an application based on the Apple Push Notification Service. There is alot of information about the client side registration and plenty of server side code examples, but I haven&#8217;t found anything that simple demonstrates how to send your device token to the provider service. The [...]]]></description>
			<content:encoded><![CDATA[<p>I am currently in the middle of designing and developing an application based on the Apple Push Notification Service. There is alot of information about the client side registration and plenty of server side code examples, but I haven&#8217;t found anything that simple demonstrates how to send your device token to the provider service.</p>
<p><span id="more-493"></span>The following code is simple (but as a newcomer to Obj-C took me ages to put together). Just press the View Source button on the following panel to see all the code (I am having trouble getting code wrapping to work, so this will be the case until I find a decent syntax highlighter plugin).</p>
<pre class="brush: cpp;">
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

	NSLog(@&quot;devToken=%@&quot;,deviceToken);

	NSString *host = @&quot;yourhost&quot;;
	NSString *URLString = @&quot;/register.php?id=&quot;;
	URLString = [URLString stringByAppendingString:id];
	URLString = [URLString stringByAppendingString:@&quot;&amp;amp;amp;amp;amp;amp;devicetoken=&quot;];

	NSString *dt = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@&quot;&amp;lt;&amp;gt;&quot;]];
	dt = [dt stringByReplacingOccurrencesOfString:@&quot; &quot; withString:@&quot;&quot;];

	URLString = [URLString stringByAppendingString:dt];
	URLString = [URLString stringByAppendingString:@&quot;&amp;amp;amp;amp;amp;amp;devicename=&quot;];
	URLString = [URLString stringByAppendingString:[[UIDevice alloc] name]];

	NSURL *url = [[NSURL alloc] initWithScheme:@&quot;http&quot; host:host path:URLString];
	NSLog(@&quot;FullURL=%@&quot;, url);

	NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];

	NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
}
</pre>
<p>If you spot the above code and think &#8220;why the hell has he done it like that&#8221;, it is because I don&#8217;t know any better at the moment. If there is a better way please leave some constructive feedback via the comment form.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thelazysysadmin.net/2009/07/apns-send-device-token-to-provider/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Simple .NET XML Tutorial</title>
		<link>http://www.thelazysysadmin.net/2009/05/simple-dotnet-xml-tutorial/</link>
		<comments>http://www.thelazysysadmin.net/2009/05/simple-dotnet-xml-tutorial/#comments</comments>
		<pubDate>Thu, 07 May 2009 02:51:08 +0000</pubDate>
		<dc:creator>Jon Smith</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.thelazysysadmin.net/?p=114</guid>
		<description><![CDATA[I needed to build an application the other day that used XML to talk to a web service, but I wanted to deal with raw XML rather then using anything based on WSDL and RPC. This was the first time I had written anything that used XML before so I started googling for code examples [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to build an application the other day that used XML to talk to a web service, but I wanted to deal with raw XML rather then using anything based on WSDL and RPC. This was the first time I had written anything that used XML before so I started googling for code examples and tutorials.</p>
<p>There wasn&#8217;t much clear documentation out there on exactly what I wanted to do so I ended up using a couple of code examples I found in the end (links provided below for original source) and modifying them for my needs.</p>
<p>The end result is extremely simple to understand (however the information was not easy to find) so I thought I would post the details here in hopes that someone else wanting to do the same thing ends up finding this article rather than searching for hours and not finding exactly what is required. (As an a-side, most of what I found online was regarding using premade XML files, and the generation of XML files and not generating and sending the XML request on the fly). Also I wasted a bit of time because of my lack of knowledge on how various Streams work together, but that is another issue entirely.</p>
<p>The following is code for C# but should apply to other .NET based languages (with an appropriate change of syntax).</p>
<p>Required Namespace Imports</p>
<pre class="brush: csharp;">
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.IO;
using System.Net;
using System.Threading;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
</pre>
<p>Code</p>
<pre class="brush: csharp;">
WebRequest req = WebRequest.Create(&quot;http://URLHERE/WebService&quot;);
req.Method = &quot;POST&quot;;
req.ContentType = &quot;text/xml&quot;;
Stream requestStream = req.GetRequestStream();

XmlTextWriter xml = new XmlTextWriter(requestStream, null);

xml.WriteStartDocument();

// The DocType will be different for most situations, this
// is what works for me.
xml.WriteDocType(&quot;Request&quot;, null, &quot;somefile.dtd&quot;, null);
xml.WriteStartElement(&quot;Request&quot;);
xml.WriteStartElement(&quot;InfoRequest&quot;);

// These values could come from any source
xml.WriteElementString(&quot;Username&quot;, &quot;&lt;&gt;&quot;);
xml.WriteElementString(&quot;Password&quot;, &quot;&lt;
&gt;&quot;);
xml.WriteElementString(&quot;Info&quot;, &quot;something&quot;);
xml.WriteEndElement();
xml.WriteEndElement();

// When Close() is called the request is sent to the server
xml.Close();

// Use a WebResponse Component to retrieve the response
WebResponse rsp = req.GetResponse();
XmlTextReader xmlin = new XmlTextReader(rsp.GetResponseStream());

while (xmlin.Read())
{
  if (xmlin.NodeType == XmlNodeType.Element)
  {
    if (xmlin.Name == &quot;Info&quot;)
    {
      String info = xmlin.ReadString();

      // Do something with returned data

    }
  }
}

xmlin.Close();
rsp.Close();
</pre>
<p>There are plenty of useful tutorials out there based on XmlTextReader and XmlTextWriter that can explain how to use them to read and write XML. So I wont cover that here. My biggest problem was finding out how to generate the XML and send it straight to the server without having to save to a file.</p>
<p>References:</p>
<ul>
<li><a href="http://www.aspsms.com/examples/c/">http://www.aspsms.com/examples/c/</a></li>
<li><a href="http://www.codeproject.com/KB/dotnet/XmlPost.aspx">http://www.codeproject.com/KB/dotnet/XmlPost.aspx</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.thelazysysadmin.net/2009/05/simple-dotnet-xml-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
