<?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>NSCoriolisBlog &#187; iPhone</title>
	<atom:link href="http://blog.coriolis.ch/category/cocoa/iphone/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.coriolis.ch</link>
	<description>Just another Coriolis weblog</description>
	<lastBuildDate>Mon, 01 Aug 2011 11:36:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Extend UIWebView to handle all special links</title>
		<link>http://blog.coriolis.ch/2009/10/29/extend-uiwebview-to-handle-all-special-links/</link>
		<comments>http://blog.coriolis.ch/2009/10/29/extend-uiwebview-to-handle-all-special-links/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 21:57:09 +0000</pubDate>
		<dc:creator>Stephan</dc:creator>
				<category><![CDATA[cocoa]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[browsing]]></category>
		<category><![CDATA[UIWebView]]></category>

		<guid isPermaLink="false">http://blog.coriolis.ch/?p=235</guid>
		<description><![CDATA[Have you ever wanted to add an UIWebView to your application, so you can browse the internets without leaving your application? While it is a trivial task to add an UIWebView to a project, there are some links that an UIWebView will not handle. These are: mailto YouTube maps.google.com iTunes AppStore I&#8217;ve written a generic [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever wanted to add an UIWebView to your application, so you can browse the internets without leaving your application? While it is a trivial task to add an UIWebView to a project, there are some links that an UIWebView will not handle.</p>
<p>These are:</p>
<ul>
<li>mailto</li>
<li>YouTube</li>
<li>maps.google.com</li>
<li>iTunes</li>
<li>AppStore</li>
</ul>
<p>I&#8217;ve written a generic BrowserViewController, code available on GitHub here: <a  href="http://github.com/sburlot/browserviewcontroller">http://github.com/sburlot/browserviewcontroller</a> which handles all these cases:</p>
<p><strong>mailto</strong> links are handled with a MFMail: I tried to handle all variations on the link: &#8220;to&#8221;, &#8220;cc&#8221;, &#8220;subject&#8221; and &#8220;body&#8221;.</p>
<p><strong>YouTube</strong>, <strong>Map</strong>, <strong>iTunes</strong> and <strong>AppStore</strong> links are opened in their respective apps.</p>
<p>You can customise the view and decide if you want a navigation tab bar or not.</p>
<p>The navigation tab bar will add standard web buttons: Back, Forward, Stop, Reload and also a button to send the url of the current page via email, or open it in Safari.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.coriolis.ch/2009/10/29/extend-uiwebview-to-handle-all-special-links/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Designing an iPhone Application: tools round up</title>
		<link>http://blog.coriolis.ch/2009/09/24/designing-an-iphone-application/</link>
		<comments>http://blog.coriolis.ch/2009/09/24/designing-an-iphone-application/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 09:44:54 +0000</pubDate>
		<dc:creator>Stephan</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[gui]]></category>
		<category><![CDATA[user interface]]></category>

		<guid isPermaLink="false">http://blog.coriolis.ch/?p=217</guid>
		<description><![CDATA[There are different schools on how to start the design of an iPhone app. Some will prefer designing on paper (I do), others will use the computer to design their next breath-taking GUI. So here is a list of some of the tools, template to design your next iPhone application. Templates: Keynote &#8217;09: via MockApp [...]]]></description>
			<content:encoded><![CDATA[<p>There are different schools on how to start the design of an iPhone app. Some will prefer designing on paper (I do), others will use the computer to design their next breath-taking GUI.</p>
<p>So here is a list of some of the tools, template to design your next iPhone application.</p>
<p>Templates:</p>
<ul>
<li>Keynote &#8217;09: <a  href="http://mockapp.com/download/">via MockApp</a></li>
<li>Microsoft PowerPoint (WTF?): <a  href="http://mockapp.com/download/">via MockApp</a></li>
<li>OmniGraffle: <a  href="http://www.graffletopia.com/stencils/413">via Patrick Crowley</a></li>
<li>OmniGraffle: <a  href="http://www.graffletopia.com/stencils/392">via Yahoo</a></li>
<li>OmniGraffle: <a  href="http://www.graffletopia.com/stencils/495"> via Designing Web Interfaces</a></li>
<li>Illustrator: <a  href="http://www.mercuryintermedia.com/blog/index.php/2009/03/iphone-ui-vector-elements">via Mercury Intermedia</a></li>
<li>PhotoShop: <a  href="http://www.teehanlax.com/blog/?p=1628">via Teehan+Lax</a></li>
</ul>
<p>Specialized Tools</p>
<ul>
<li><a  href="http://www.balsamiq.com/">Balsamiq Mockups</a></li>
</ul>
<p>For pen &#038; paper aficionados:</p>
<ul>
<li>Stainless steel stencil: <a  href="http://www.designcommission.com/shop/iphone-stencil-kit/">iPhone Stencil Kit</a></li>
<li>DesignCommission also provides a <a  href="http://www.designcommission.com/shop/iphone-stencil-kit/">PDF template</a>
<li>Sketch Paper in pdf: <a  href="http://labs.boulevart.be/index.php/2008/06/05/sketch-paper-for-the-mobile-designer/">on labs.boulevard</a></li>
<li>Printed SketchBook: <a  href="http://www.mobilesketchbook.com/">Kaplan Software Group</a></li>
</ul>
<p>In <a  href="http://www.pragprog.com/titles/ahptl/pragmatic-thinking-and-learning">Pragmatic Thinking and Learning: Refactor Your Wetware</a>, Andy Hunt recommends using pen and paper to use your right brain and free your creative mind. When using a computer, you will concentrate on the details, not the complete user experience.</p>
<p>Another drawback of using a computer: if you show your design to the client, he also will concentrate on the details (&#8220;can you change the shade of this red button? It&#8217;s TOO red.&#8221;). Showing a hand-drawn design will let him <em>imagine</em> how the final product will look. This can be a double-edged sword, so you better know what the customer is expecting before using one of these techniques.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.coriolis.ch/2009/09/24/designing-an-iphone-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Arbitrary rotation of a CGImage</title>
		<link>http://blog.coriolis.ch/2009/09/04/arbitrary-rotation-of-a-cgimage/</link>
		<comments>http://blog.coriolis.ch/2009/09/04/arbitrary-rotation-of-a-cgimage/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 09:13:50 +0000</pubDate>
		<dc:creator>Stephan</dc:creator>
				<category><![CDATA[cocoa]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[cgimage]]></category>
		<category><![CDATA[cgimageref]]></category>
		<category><![CDATA[rotation]]></category>

		<guid isPermaLink="false">http://blog.coriolis.ch/?p=206</guid>
		<description><![CDATA[For my current project, I have to rotate a CGImageRef by an arbitrary angle. Here is the code: - (CGImageRef)CGImageRotatedByAngle:(CGImageRef)imgRef angle:(CGFloat)angle { CGFloat angleInRadians = angle * (M_PI / 180); CGFloat width = CGImageGetWidth(imgRef); CGFloat height = CGImageGetHeight(imgRef); CGRect imgRect = CGRectMake(0, 0, width, height); CGAffineTransform transform = CGAffineTransformMakeRotation(angleInRadians); CGRect rotatedRect = CGRectApplyAffineTransform(imgRect, transform); CGColorSpaceRef [...]]]></description>
			<content:encoded><![CDATA[<p>For my current project, I have to rotate a CGImageRef by an arbitrary angle.</p>
<p>Here is the code:</p>
<pre><code>
- (CGImageRef)CGImageRotatedByAngle:(CGImageRef)imgRef angle:(CGFloat)angle
{
  CGFloat angleInRadians = angle * (M_PI / 180);
  CGFloat width = CGImageGetWidth(imgRef);
  CGFloat height = CGImageGetHeight(imgRef);

  CGRect imgRect = CGRectMake(0, 0, width, height);
  CGAffineTransform transform = CGAffineTransformMakeRotation(angleInRadians);
  CGRect rotatedRect = CGRectApplyAffineTransform(imgRect, transform);

  CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
  CGContextRef bmContext = CGBitmapContextCreate(NULL,
                                                 rotatedRect.size.width,
                                                 rotatedRect.size.height,
                                                 8,
                                                 0,
                                                 colorSpace,
                                                 kCGImageAlphaPremultipliedFirst);
  CGContextSetAllowsAntialiasing(bmContext, FALSE);
  CGContextSetInterpolationQuality(bmContext, kCGInterpolationNone);
  CGColorSpaceRelease(colorSpace);
  CGContextTranslateCTM(bmContext,
                        +(rotatedRect.size.width/2),
                        +(rotatedRect.size.height/2));
  CGContextRotateCTM(bmContext, angleInRadians);
  CGContextTranslateCTM(bmContext,
                        -(rotatedRect.size.width/2),
                        -(rotatedRect.size.height/2));
  CGContextDrawImage(bmContext, CGRectMake(0, 0,
                                           rotatedRect.size.width,
                                           rotatedRect.size.height),
                     imgRef);

  CGImageRef rotatedImage = CGBitmapContextCreateImage(bmContext);
  CFRelease(bmContext);
  [(id)rotatedImage autorelease];

  return rotatedImage;
}
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.coriolis.ch/2009/09/04/arbitrary-rotation-of-a-cgimage/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Apple Push Notification Service Gateways</title>
		<link>http://blog.coriolis.ch/2009/08/07/apple-push-notification-service-gateways/</link>
		<comments>http://blog.coriolis.ch/2009/08/07/apple-push-notification-service-gateways/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 18:32:14 +0000</pubDate>
		<dc:creator>Stephan</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[apn]]></category>
		<category><![CDATA[push]]></category>

		<guid isPermaLink="false">http://blog.coriolis.ch/?p=183</guid>
		<description><![CDATA[I&#8217;ve not yet had the request to implement Push in an iPhone app, but a thread on the Developer Forums gave me a hint: Some companies are already providing (or planning to provide) a gateway to the APN: These are: Urban Airship iLime AppNotify These are in closed beta: Push.io iPushServer.com msgpush Urban Airship and [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve not yet had the request to implement Push in an iPhone app, but a thread on the Developer Forums gave me a hint:</p>
<p>Some companies are already providing (or planning to provide) a gateway to the APN:</p>
<p>These are:</p>
<ul>
<li><a  href="http://urbanairship.com">Urban Airship</a></li>
<li><a  href="http://www.ilime.com/">iLime</a></li>
<li><a  href="http://www.appnotify.com/">AppNotify</a></li>
</ul>
<p>These are in closed beta:</p>
<ul>
<li><a  href="http://push.io/">Push.io</a></li>
<li><a  href="http://www.ipushserver.com/">iPushServer.com</a></li>
<li><a  href="http://msgpush.com/">msgpush</a></li>
</ul>
<p>Urban Airship and iLime also provide In App Purchase.</p>
<p>Or you can build your own: <strong>Open Source &#038; Tutorials</strong></p>
<ul>
<li><a  href="http://code.google.com/p/apns-php/">ApnsPHP: Apple Push Notification &#038; Feedback Provider</a></li>
<li><a  href="http://www.easyapns.com/">EasyAPNS: Open Source solution (PHP, MySQL)</a></li>
<li><a  href="http://blog.boxedice.com/2009/07/10/how-to-build-an-apple-push-notification-provider-server-tutorial/">Tutorial on how to setup your own server in PHP</a></li>
<li><a  href="http://code.google.com/p/php-apns/">Source code (in PHP), requires PHP with memcache</a></li>
<li><a  href="http://code.google.com/p/apns-python-wrapper/">Python wrapper for Apple Push Notification Service</a></li>
<li><a  href="http://pyapns.org/">A universal Apple Push Notification Service (APNS) provider in Python</a></li>
<li><a  href="http://chrismoos.com/2009/07/13/apple-push-notification-library-for-haskell/">Apple Push Notification Library for Haskell</a></li>
<li><a  href="http://github.com/thegeekbird/Apns4r/tree/master">Apple Push Notification Library for Ruby</a></li>
<li><a  href="http://github.com/samsoffes/apple_push_notification">Rails plugin for Apple Push Notifications</a></li>
<li><a  href="http://github.com/markbates/apn_on_rails/tree/master">Apple Push Notifications on Rails</a></li>
<li><a  href="http://code.google.com/p/apns-sharp/">Apple Push Notification &#038; Feedback Services Client C# Library</a></li>
<li><a  href="http://github.com/aufflick/p5-net-apns-persistent"> Persistent Apple APNS interface for Perl 5</a></li>
</ul>
<p>I will try to keep this list updated.</p>
<p>Edit: added ApnsPHP &#038; pyapns.org<br />
Edit: separated the active services from the beta, added msgpush.com and C# Library<br />
Edit: added a Rails plugin<br />
Edit: added AppNotify (in Beta)<br />
Edit: AppNotify is no more in Beta.<br />
Edit: Added EasyAPNS source code<br />
Edit: Removed <a  href="http://www.httpush.com/">Bigcurl HTTPush</a>, since it&#8217;s reserved for <a  href="http://www.bigcurl.de/">bigcurl  agency</a> customers<br />
Edit: added a Perl module</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.coriolis.ch/2009/08/07/apple-push-notification-service-gateways/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Increase the responsiveness of your UITableViews</title>
		<link>http://blog.coriolis.ch/2009/05/04/increase-the-responsiveness-of-your-uitableviews/</link>
		<comments>http://blog.coriolis.ch/2009/05/04/increase-the-responsiveness-of-your-uitableviews/#comments</comments>
		<pubDate>Mon, 04 May 2009 08:36:36 +0000</pubDate>
		<dc:creator>Stephan</dc:creator>
				<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://blog.coriolis.ch/?p=167</guid>
		<description><![CDATA[Let&#8217;s say you have an UITableView in which rows, when touched, changes the display to another view with an animation. If you touch quickly a row, the row will highlight just before the animation starts. If the action performed when touching the row takes some time (let&#8217;s say more than 0.5 seconds), after having touched [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say you have an UITableView in which rows, when touched, changes the display to another view with an animation.</p>
<p>If you touch quickly a row, the row will highlight just before the animation starts.</p>
<p>If the action performed when touching the row takes some time (let&#8217;s say more than 0.5 seconds), after having touched the row, nothing will be visible while your code is running <strong>then </strong>the row will highlight and the animation will happen.</p>
<p>To make the row highlight immediately, so the user has a immediate feedback on its action, do this:</p>
<p>Change the name of your method<br />
<strong>- (void)tableView:(UITableView *)_tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath</strong></p>
<p>to</p>
<p><strong>- (void) didSelectRowAtIndexPath:(NSIndexPath *)indexPath</strong></p>
<p>And add this method to your view controller:</p>
<pre><code>
- (void)tableView:(UITableView *)_tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  [self performSelector:@selector(didSelectRowAtIndexPath:) withObject:indexPath afterDelay:0.1f];
}</code></pre>
<p>The feedback when touching a row is immediate and will greatly improve the subjective responsiveness of your application (IMHO).</p>
<p>(via the <a  href="http://blog.instapaper.com/">Instapaper blog</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.coriolis.ch/2009/05/04/increase-the-responsiveness-of-your-uitableviews/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Relative date to now</title>
		<link>http://blog.coriolis.ch/2009/02/20/relative-date-to-now/</link>
		<comments>http://blog.coriolis.ch/2009/02/20/relative-date-to-now/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 10:34:58 +0000</pubDate>
		<dc:creator>Stephan</dc:creator>
				<category><![CDATA[cocoa]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[NSDate]]></category>
		<category><![CDATA[NSDateComponents]]></category>
		<category><![CDATA[relative date]]></category>

		<guid isPermaLink="false">http://blog.coriolis.ch/?p=128</guid>
		<description><![CDATA[In my current project, I needed to know if a given NSDate was today, yesterday or earlier. Simple task, I thought. Until I looked at the documentation for NSCalendar, NSDateComponents and NSDate. While these are extremely powerful, I am not proud of the code I&#8217;ve written. It should be easier. Anyway, the code below will [...]]]></description>
			<content:encoded><![CDATA[<p>In my current project, I needed to know if a given NSDate was today, yesterday or earlier. Simple task, I thought. Until I looked at the documentation for <strong>NSCalendar</strong>, <strong>NSDateComponents</strong> and <strong>NSDate</strong>. While these are extremely powerful, I am not proud of the code I&#8217;ve written. It should be easier.</p>
<p>Anyway, the code below will take a date and return a formatted version relative from today:</p>
<ul>
<li>Today, 11h35</li>
<li>Yesterday, 8h27</li>
<li>January 12, 22h27</li>
</ul>
<p><span id="more-128"></span></p>
<pre><code>- (NSString *) formattedDateRelativeToNow:(NSDate *)date
{
  NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init]  autorelease];

  NSCalendar *gregorian = [[NSCalendar alloc]
                                initWithCalendarIdentifier:NSGregorianCalendar];
  NSDateComponents *newsComponents = [gregorian components:(NSYearCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit)
                                                  fromDate:date];
  [newsComponents setHour:0];
  [newsComponents setMinute:0];
  [newsComponents setSecond:0];
  NSDate *dateAtMidnight =  [gregorian dateFromComponents:newsComponents];
  NSInteger dayDiff = [[gregorian components:(NSDayCalendarUnit)
                                    fromDate:dateAtMidnight
                                      toDate:[NSDate date]
                                     options:0]
                                              day];

  if (dayDiff == 0) {
    [dateFormatter setDateFormat:@"'today, 'H'h'mm"];
  } else {
    if (dayDiff == 1) {
      [dateFormatter setDateFormat:@"'yesterday, 'H'h'mm"];
    } else {
      [dateFormatter setDateFormat:@"MMMM d, H'h'mm"];
    }
  }
  [gregorian release];
  return [dateFormatter stringFromDate:date];
}
</code></pre>
<p>After having written this code, I found these similar posts on the subject (look at the answers given by mmalc &#8211; Malcolm Crawford):</p>
<ul>
<li><a  href="http://stackoverflow.com/questions/185780/modifying-nsdate-to-represent-1-month-from-today/186104#186104">Modifying NSDate to represent 1 month from today</a></li>
<li><a  href="http://stackoverflow.com/questions/181459/is-there-a-better-way-to-find-midnight-tomorrow/181495#181495">Is there a better way to find midnight tomorrow?</a></li>
</ul>
<p><strong>Hint</strong>: if you display relative dates in your project, on the iPhone you should handle the &#8220;<strong>UIApplicationSignificantTimeChangeNotification</strong>&#8221; notification.</p>
<p><strong>Update</strong>: I knew there was an easier way. Solution by <a  href="http://seriot.ch/">Nicolas Seriot</a>:</p>
<pre><code>- (NSString *) formattedDateRelativeToNow2:(NSDate *)date {
  NSDateFormatter *mdf = [[NSDateFormatter alloc] init];
  [mdf setDateFormat:@"yyyy-MM-dd"];
  NSDate *midnight = [mdf dateFromString:[mdf stringFromDate:date]];
  [mdf release];

  NSUInteger dayDiff = (int)[midnight timeIntervalSinceNow] / (60*60*24);

  NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];

  switch(dayDiff) {
    case 0:
      [dateFormatter setDateFormat:@"'today, 'H'h'mm"]; break;
    case -1:
      [dateFormatter setDateFormat:@"'yesterday, 'H'h'mm"]; break;
    default:
      [dateFormatter setDateFormat:@"MMMM d, H'h'mm"];
  }

  return [dateFormatter stringFromDate:date];
}</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.coriolis.ch/2009/02/20/relative-date-to-now/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Reading the battery level programmatically</title>
		<link>http://blog.coriolis.ch/2009/02/14/reading-the-battery-level-programmatically/</link>
		<comments>http://blog.coriolis.ch/2009/02/14/reading-the-battery-level-programmatically/#comments</comments>
		<pubDate>Sat, 14 Feb 2009 13:25:06 +0000</pubDate>
		<dc:creator>Stephan</dc:creator>
				<category><![CDATA[cocoa]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[battery]]></category>
		<category><![CDATA[battery level]]></category>

		<guid isPermaLink="false">http://blog.coriolis.ch/?p=106</guid>
		<description><![CDATA[A beta-tester was complaining the application was draining its battery. To check if this was really the case, I needed to get the battery level with a better accuracy than just looking at the battery icon. So I used this little routine to check. This routine is adapted from a post on MacRumors.com. It uses [...]]]></description>
			<content:encoded><![CDATA[<p>A beta-tester was complaining the application was draining its battery. To check if this was really the case, I needed to get the battery level with a better accuracy than just looking at the battery icon. So I used this little routine to check.</p>
<p>This routine is adapted from a <a  href="http://forums.macrumors.com/showthread.php?t=474628">post</a> on MacRumors.com.</p>
<p><span id="more-106"></span></p>
<p>It uses non-approved calls, so don&#8217;t post your application with this code or you may be rejected!</p>
<p>The method I used was:</p>
<ul>
<li>Copy the <strong>IOPowerSources.h</strong> and <strong>IOPSKeys.h</strong> from the Simulator into my project</li>
<li>Add the <strong>libIOKit.A.dylib</strong> from the iPhone to my project</li>
</ul>
<p>To get a copy of the libIOKit.A.dylib without jailbreaking my iPhone, I used <a  href="http://code.google.com/p/fswalker/">FSWalker</a> from <a  href="http://seriot.ch">Nicolas Seriot</a>, a nifty utility which creates a web server on your iPhone and allows you to navigate your iPhone file system with a web browser.</p>
<p>So launch FSWalker, and with your browser go to http://192.168.2.100:20000/System/Library/Frameworks/IOKit.framework/Versions/A (replace the IP address with the address of your iPhone).<br />
Download the IOKit file and add it to your project with the name &#8220;libIOKit.A.dylib&#8221;.</p>
<pre><code>#include "IOPowerSources.h"
#include "IOPSKeys.h"

- (double) batteryLevel
{
  CFTypeRef blob = IOPSCopyPowerSourcesInfo();
  CFArrayRef sources = IOPSCopyPowerSourcesList(blob);

  CFDictionaryRef pSource = NULL;
  const void *psValue;

  int numOfSources = CFArrayGetCount(sources);
  if (numOfSources == 0) {
    NSLog(@"Error in CFArrayGetCount");
    return -1.0f;
  }

  for (int i = 0 ; i < numOfSources ; i++)
  {
    pSource = IOPSGetPowerSourceDescription(blob, CFArrayGetValueAtIndex(sources, i));
    if (!pSource) {
      NSLog(@"Error in IOPSGetPowerSourceDescription");
      return -1.0f;
    }
    psValue = (CFStringRef)CFDictionaryGetValue(pSource, CFSTR(kIOPSNameKey));

    int curCapacity = 0;
    int maxCapacity = 0;
    double percent;

    psValue = CFDictionaryGetValue(pSource, CFSTR(kIOPSCurrentCapacityKey));
    CFNumberGetValue((CFNumberRef)psValue, kCFNumberSInt32Type, &#038;curCapacity);

    psValue = CFDictionaryGetValue(pSource, CFSTR(kIOPSMaxCapacityKey));
    CFNumberGetValue((CFNumberRef)psValue, kCFNumberSInt32Type, &#038;maxCapacity);

    percent = ((double)curCapacity/(double)maxCapacity * 100.0f);

    return percent;
  }
  return -1.0f;
}</code></pre>
<p>Don't forget to remove the headers and libIOKit.A.dylib from your code before shipping!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.coriolis.ch/2009/02/14/reading-the-battery-level-programmatically/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Redirect NSLog to a file on the iPhone</title>
		<link>http://blog.coriolis.ch/2009/01/09/redirect-nslog-to-a-file-on-the-iphone/</link>
		<comments>http://blog.coriolis.ch/2009/01/09/redirect-nslog-to-a-file-on-the-iphone/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 20:42:33 +0000</pubDate>
		<dc:creator>Stephan</dc:creator>
				<category><![CDATA[cocoa]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[nslog]]></category>
		<category><![CDATA[redirect]]></category>

		<guid isPermaLink="false">http://blog.coriolis.ch/?p=85</guid>
		<description><![CDATA[If you need to debug your app when disconnected from your Mac (and from the console), redirect all your NSLog calls to a file so you can later read it. The method below will create a file name &#8220;console.log&#8221; in the Documents folder of your application so you can later read it. Just call this [...]]]></description>
			<content:encoded><![CDATA[<p>If you need to debug your app when disconnected from your Mac (and from the console), redirect all your NSLog calls to a file so you can later read it.</p>
<p>The method below will create a file name &#8220;console.log&#8221; in the <strong>Documents</strong> folder of your application so you can later read it.</p>
<p>Just call this method in your program:</p>
<pre><code>- (void) redirectConsoleLogToDocumentFolder
{
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                       NSUserDomainMask, YES);
  NSString *documentsDirectory = [paths objectAtIndex:0];
  NSString *logPath = [documentsDirectory
                       stringByAppendingPathComponent:@"console.log"];
  freopen([logPath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
}</code></pre>
<p>The log will never be erased, so use with caution.</p>
<p><span id="more-85"></span></p>
<p>Once you have tested your app in the filed, reconnect your phone to your Mac and in Xcode, open the Organizer.<br />
In the Summary panel, you have the list of all the apps on your phone. Expand the one you&#8217;re debugging, and you&#8217;ll a package named &#8220;Application Data&#8221;.<br />
<div id="attachment_95" class="wp-caption aligncenter" style="width: 310px"><img src="http://blog.coriolis.ch/wp-content/uploads/2009/01/image-7-300x136.jpg" alt="Xcode Organizer" title="Xcode Organizer" width="300" height="136" class="size-medium wp-image-95" /><p class="wp-caption-text">Xcode Organizer</p></div><br />
Click the arrow on the right of its name and save this. You&#8217;ll end with a folder with a name of your Bundle Identifier followed by a date.</p>
<p>Inside this folder you&#8217;ll find your Documents Folder, which should contain the console.log.</p>
<p>Happy debugging.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.coriolis.ch/2009/01/09/redirect-nslog-to-a-file-on-the-iphone/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Macros for Xcode</title>
		<link>http://blog.coriolis.ch/2009/01/05/macros-for-xcode/</link>
		<comments>http://blog.coriolis.ch/2009/01/05/macros-for-xcode/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 10:02:56 +0000</pubDate>
		<dc:creator>Stephan</dc:creator>
				<category><![CDATA[cocoa]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[nslog]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://blog.coriolis.ch/?p=65</guid>
		<description><![CDATA[These are some of the macros I use with Xcode: CMLog: I use this macro to replace NSLog: #define CMLog(format, ...) NSLog(@"%s:%@", __PRETTY_FUNCTION__,[NSString stringWithFormat:format, ## __VA_ARGS__]); When you use this macro, it outputs text to the console, including the class and method from where it was called. So, if you call this macro from the [...]]]></description>
			<content:encoded><![CDATA[<p>These are some of the macros I use with Xcode:</p>
<p><strong>CMLog</strong>: I use this macro to replace NSLog:</p>
<pre><code>#define CMLog(format, ...) NSLog(@"%s:%@", __PRETTY_FUNCTION__,[NSString stringWithFormat:format, ## __VA_ARGS__]);
</code></pre>
<p>When you use this macro, it outputs text to the console, including the class and method from where it was called. So, if you call this macro from the class <strong>MyAppDelegate</strong> and the method <strong>applicationDidFinishLaunching</strong>,</p>
<pre><code>CMLog(@"My iPhone is an %@, v %@", [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion]);</code></pre>
<p>you get this in the console:<br />
<span id="more-65"></span></p>
<pre><code>2009-01-05 10:06:28.957 MyApp15173:20b] -[MyAppDelegate applicationDidFinishLaunching:]:My iPhone is an iPhone Simulator, v 2.2</code></pre>
<p><strong>MARK</strong>: I use this macro to just output the name of class and method it was called from. Useful to know if a method was called.</p>
<pre><code>#define MARK	CMLog(@"%s", __PRETTY_FUNCTION__);
</code></pre>
<p><strong>START_TIMER</strong> and <strong>END_TIMER</strong>: These are for benchmarking a method:</p>
<pre><code>#define START_TIMER NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
#define END_TIMER(msg) 	NSTimeInterval stop = [NSDate timeIntervalSinceReferenceDate]; CMLog([NSString stringWithFormat:@"%@ Time = %f", msg, stop-start]);
</code></pre>
<p>Just put a <strong>START_TIMER</strong> at the beginning of the block to benchmark, and <strong>END_TIMER</strong> and the end, and you&#8217;ll get the timing.</p>
<pre><code>- (NSData *)loadDataFromURL:(NSString *)dataURL
{
  START_TIMER;
  NSData *data = [self doSomeStuff:dataURL];
  END_TIMER(@"loadDataFromURL");
  return data;
}
</code></pre>
<p>Will output:</p>
<pre><code>2009-01-05 10:31:37.943 MyApp[15283:20b] -[MyAppDelegate loadDataFromURL:]:loadDataFromURL Time = 3.636021
</code></pre>
<p>Now wrap all these declarations in your precompiled header, using a conditional flag. This flag will be set to 1 for Debug, and 0 for release, so your app will not fill the console with output.</p>
<pre><code>#if DEBUG==1
#define CMLog(format, ...) NSLog(@"%s:%@", __PRETTY_FUNCTION__,[NSString stringWithFormat:format, ## __VA_ARGS__]);
#define MARK	CMLog(@"%s", __PRETTY_FUNCTION__);
#define START_TIMER NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
#define END_TIMER(msg) 	NSTimeInterval stop = [NSDate timeIntervalSinceReferenceDate]; CMLog([NSString stringWithFormat:@"%@ Time = %f", msg, stop-start]);
#else
#define CMLog(format, ...)
#define MARK
#define START_TIMER
#define END_TIMER(msg)
#endif
</code></pre>
<p>Just add this to your <em>Debug</em> target setting</p>
<pre><code>OTHER_CFLAGS = -DDEBUG=1
</code></pre>
<p>and this to your <em>Release</em> target setting:</p>
<pre><code>OTHER_CFLAGS = -DDEBUG=0
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.coriolis.ch/2009/01/05/macros-for-xcode/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>HowTo fit text inside a UIWebView</title>
		<link>http://blog.coriolis.ch/2009/01/05/howto-fit-text-inside-a-uiwebview/</link>
		<comments>http://blog.coriolis.ch/2009/01/05/howto-fit-text-inside-a-uiwebview/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 22:25:14 +0000</pubDate>
		<dc:creator>Stephan</dc:creator>
				<category><![CDATA[cocoa]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[fit text]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[UIWebView]]></category>

		<guid isPermaLink="false">http://blog.coriolis.ch/?p=45</guid>
		<description><![CDATA[If, like me, you want to make sure your text will fit inside your UIWebView (without scrolling), you can implement the following javascript: &#60;script language=&#x27;javascript&#x27; type=&#34;text/javascript&#34;&#62; function adjustHeight(maxHeight) { elem = document.getElementById(&#34;sign&#34;); height = elem.offsetHeight; current_size = elem.style.fontSize.replace(&#x27;px&#x27;,&#x27;&#x27;)/1; while ((current_size-- &#62; 10) &#38;&#38; (height &#62; maxHeight)){ elem.style.fontSize = current_size + &#x27;px&#x27;; height = elem.offsetHeight; } [...]]]></description>
			<content:encoded><![CDATA[<p>If, like me, you want to make sure your text will fit inside your UIWebView (without scrolling), you can implement the following javascript:</p>
<pre><code>    &lt;script language=&#x27;javascript&#x27; type=&quot;text/javascript&quot;&gt;
    function adjustHeight(maxHeight) {
      elem = document.getElementById(&quot;sign&quot;);
      height = elem.offsetHeight;
      current_size = elem.style.fontSize.replace(&#x27;px&#x27;,&#x27;&#x27;)/1;
      while ((current_size-- &gt; 10) &amp;&amp; (height &gt; maxHeight)){
        elem.style.fontSize = current_size + &#x27;px&#x27;;
        height = elem.offsetHeight;
      }
    }
    &lt;/script&gt;
</code></pre>
<p>This script will reduce the size of the div until it fits the required height, but with a minimum font-size of 10px hardcoded.</p>
<p>Now in the html, call the adjustHeight function, passing it the id of the div to adjust:</p>
<pre><code>&lt;body onload=&quot;adjustHeight(48)&quot;&gt;
  &lt;div id=&quot;sign&quot; style=&quot;font-size:68px&quot;&gt;This is the text that fits&lt;/div&gt;
&lt;/body&gt;
</code></pre>
<p>The trick here is that to read the fontSize of a div, the font-size property should be inline. If the font-size is declared in the CSS, you&#8217;ll have to use another much more complex method, described in <a  href="http://developer.apple.com/internet/webcontent/styles.html">http://developer.apple.com/internet/webcontent/styles.html</a>.</p>
<p>PS: Instead of reading the font-size from the div, I could have hardcoded its value in the script, and avoided much trouble.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.coriolis.ch/2009/01/05/howto-fit-text-inside-a-uiwebview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced

Served from: www.coriolis.ch @ 2012-02-04 23:36:15 -->
