<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Reading the battery level programmatically</title>
	<atom:link href="http://blog.coriolis.ch/2009/02/14/reading-the-battery-level-programmatically/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.coriolis.ch/2009/02/14/reading-the-battery-level-programmatically/</link>
	<description>Just another Coriolis weblog</description>
	<lastBuildDate>Sat, 06 Aug 2011 21:59:33 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
	<item>
		<title>By: salman Ahmed</title>
		<link>http://blog.coriolis.ch/2009/02/14/reading-the-battery-level-programmatically/comment-page-1/#comment-12091</link>
		<dc:creator>salman Ahmed</dc:creator>
		<pubDate>Mon, 03 Jan 2011 06:18:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.coriolis.ch/?p=106#comment-12091</guid>
		<description>AT command AT+CBC gives the battery level with 1 % accuracy 
But dont know if apple will allow it aur not . though I have implemented
:)</description>
		<content:encoded><![CDATA[<p>AT command AT+CBC gives the battery level with 1 % accuracy<br />
But dont know if apple will allow it aur not . though I have implemented<br />
 <img src='http://blog.coriolis.ch/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephan</title>
		<link>http://blog.coriolis.ch/2009/02/14/reading-the-battery-level-programmatically/comment-page-1/#comment-6389</link>
		<dc:creator>Stephan</dc:creator>
		<pubDate>Mon, 25 Jan 2010 23:10:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.coriolis.ch/?p=106#comment-6389</guid>
		<description>Stuart,

You are right, you have to change all &quot;return -1.0f&quot; by &quot;return nil&quot;.

Better, you should replace all &quot;return -1.0f&quot; and the last line: &quot;return nil&quot; by:
return [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:-1], @&quot;curCapacity&quot;, [NSNumber numberWithInt:-1], @&quot;maxCapacity&quot;, nil];;

So in your code, you should do:

int level = [[[self batteryData] objectForKey:@&quot;curCapacity&quot;] intValue];
curCapacity.text = [NSString stringWithFormat:@&quot;%d mAh&quot;, curCapacity];

Note that level is now an int, not a float.

HTH,
Stephan</description>
		<content:encoded><![CDATA[<p>Stuart,</p>
<p>You are right, you have to change all &#8220;return -1.0f&#8221; by &#8220;return nil&#8221;.</p>
<p>Better, you should replace all &#8220;return -1.0f&#8221; and the last line: &#8220;return nil&#8221; by:<br />
return [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:-1], @&#8221;curCapacity&#8221;, [NSNumber numberWithInt:-1], @&#8221;maxCapacity&#8221;, nil];;</p>
<p>So in your code, you should do:</p>
<p>int level = [[[self batteryData] objectForKey:@&#8221;curCapacity&#8221;] intValue];<br />
curCapacity.text = [NSString stringWithFormat:@"%d mAh", curCapacity];</p>
<p>Note that level is now an int, not a float.</p>
<p>HTH,<br />
Stephan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart Forbes</title>
		<link>http://blog.coriolis.ch/2009/02/14/reading-the-battery-level-programmatically/comment-page-1/#comment-6387</link>
		<dc:creator>Stuart Forbes</dc:creator>
		<pubDate>Mon, 25 Jan 2010 19:00:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.coriolis.ch/?p=106#comment-6387</guid>
		<description>Thanks Stephan, 

I have done this but get the error &quot;incompatible types in return&quot; at the other two instances of return 1.0f; Should these be return nil; also?

Before I used double level = [self batteryLevel]; when I was using your code to return a percent value. I then put the variable &#039;level&#039; into the required label.  How exactly would I put the value for curCapacity into a label now that NSDictionary is being used?  I tried:

double level = [self batteryData];
curCapacity.text = [NSString stringWithFormat:@&quot;%.2f %&quot;, curCapacity];

This did not work. Please note I changed:

 - (double) batteryLevel;

In the .h file to:

- (NSDictionary *) batteryData;

Thanks once again for your help! I hope you can understand what I mean.
Stuart</description>
		<content:encoded><![CDATA[<p>Thanks Stephan, </p>
<p>I have done this but get the error &#8220;incompatible types in return&#8221; at the other two instances of return 1.0f; Should these be return nil; also?</p>
<p>Before I used double level = [self batteryLevel]; when I was using your code to return a percent value. I then put the variable &#8216;level&#8217; into the required label.  How exactly would I put the value for curCapacity into a label now that NSDictionary is being used?  I tried:</p>
<p>double level = [self batteryData];<br />
curCapacity.text = [NSString stringWithFormat:@"%.2f %", curCapacity];</p>
<p>This did not work. Please note I changed:</p>
<p> &#8211; (double) batteryLevel;</p>
<p>In the .h file to:</p>
<p>- (NSDictionary *) batteryData;</p>
<p>Thanks once again for your help! I hope you can understand what I mean.<br />
Stuart</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephan</title>
		<link>http://blog.coriolis.ch/2009/02/14/reading-the-battery-level-programmatically/comment-page-1/#comment-6173</link>
		<dc:creator>Stephan</dc:creator>
		<pubDate>Mon, 11 Jan 2010 10:54:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.coriolis.ch/?p=106#comment-6173</guid>
		<description>Stuart,

Just change the definition of the method to:

&lt;code&gt;- (NSDictionary *) batteryData&lt;/code&gt;

Then replace the

&lt;code&gt;return percent;&lt;/code&gt;
by
&lt;code&gt;return [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:curCapacity], @&quot;curCapacity&quot;, [NSNumber numberWithInt:maxCapacity], @&quot;maxCapacity&quot;, nil];&lt;/code&gt;

also replace the last line to 

&lt;code&gt;return nil;&lt;/code&gt;

That should do the trick.</description>
		<content:encoded><![CDATA[<p>Stuart,</p>
<p>Just change the definition of the method to:</p>
<p><code>- (NSDictionary *) batteryData</code></p>
<p>Then replace the</p>
<p><code>return percent;</code><br />
by<br />
<code>return [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:curCapacity], @"curCapacity", [NSNumber numberWithInt:maxCapacity], @"maxCapacity", nil];</code></p>
<p>also replace the last line to </p>
<p><code>return nil;</code></p>
<p>That should do the trick.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart</title>
		<link>http://blog.coriolis.ch/2009/02/14/reading-the-battery-level-programmatically/comment-page-1/#comment-6162</link>
		<dc:creator>Stuart</dc:creator>
		<pubDate>Sun, 10 Jan 2010 19:13:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.coriolis.ch/?p=106#comment-6162</guid>
		<description>Hello Stephan,
How would I use a similar thing, but return maxCapacity and curCapacity individually rather than percent?

Thanks in advance,
Stu</description>
		<content:encoded><![CDATA[<p>Hello Stephan,<br />
How would I use a similar thing, but return maxCapacity and curCapacity individually rather than percent?</p>
<p>Thanks in advance,<br />
Stu</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart Forbes</title>
		<link>http://blog.coriolis.ch/2009/02/14/reading-the-battery-level-programmatically/comment-page-1/#comment-6089</link>
		<dc:creator>Stuart Forbes</dc:creator>
		<pubDate>Tue, 05 Jan 2010 14:08:05 +0000</pubDate>
		<guid isPermaLink="false">http://blog.coriolis.ch/?p=106#comment-6089</guid>
		<description>I have sorted the undeclared problem. My apologies!</description>
		<content:encoded><![CDATA[<p>I have sorted the undeclared problem. My apologies!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart Forbes</title>
		<link>http://blog.coriolis.ch/2009/02/14/reading-the-battery-level-programmatically/comment-page-1/#comment-6085</link>
		<dc:creator>Stuart Forbes</dc:creator>
		<pubDate>Tue, 05 Jan 2010 10:57:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.coriolis.ch/?p=106#comment-6085</guid>
		<description>Hello Stephan,
Is it possible to get the values for curCapacity and maxCapacity using this method, and use them in different calculations? I have tried using them, but I get the error &#039;undeclared&#039;.</description>
		<content:encoded><![CDATA[<p>Hello Stephan,<br />
Is it possible to get the values for curCapacity and maxCapacity using this method, and use them in different calculations? I have tried using them, but I get the error &#8216;undeclared&#8217;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephan</title>
		<link>http://blog.coriolis.ch/2009/02/14/reading-the-battery-level-programmatically/comment-page-1/#comment-5658</link>
		<dc:creator>Stephan</dc:creator>
		<pubDate>Wed, 02 Dec 2009 07:35:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.coriolis.ch/?p=106#comment-5658</guid>
		<description>If you dont use the 3.0 SDK, there is no approved way of reading the battery level.</description>
		<content:encoded><![CDATA[<p>If you dont use the 3.0 SDK, there is no approved way of reading the battery level.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hans</title>
		<link>http://blog.coriolis.ch/2009/02/14/reading-the-battery-level-programmatically/comment-page-1/#comment-5657</link>
		<dc:creator>Hans</dc:creator>
		<pubDate>Wed, 02 Dec 2009 02:22:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.coriolis.ch/?p=106#comment-5657</guid>
		<description>But, if I remove the libIOKit.A.dylib I can&#039;t use this routine and its APIs. Am I right? Or Is there another way to read the battery level programmatically without using the SDK 3.0 APIs(5%)? If I can&#039;t use your routine because Apple wouldn&#039;t allow private APIs, do you know any other way to do that (using C language for instance)?

Thanks for your help.</description>
		<content:encoded><![CDATA[<p>But, if I remove the libIOKit.A.dylib I can&#8217;t use this routine and its APIs. Am I right? Or Is there another way to read the battery level programmatically without using the SDK 3.0 APIs(5%)? If I can&#8217;t use your routine because Apple wouldn&#8217;t allow private APIs, do you know any other way to do that (using C language for instance)?</p>
<p>Thanks for your help.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stephan</title>
		<link>http://blog.coriolis.ch/2009/02/14/reading-the-battery-level-programmatically/comment-page-1/#comment-5654</link>
		<dc:creator>Stephan</dc:creator>
		<pubDate>Tue, 01 Dec 2009 22:45:56 +0000</pubDate>
		<guid isPermaLink="false">http://blog.coriolis.ch/?p=106#comment-5654</guid>
		<description>Just remove the libIOKit.A.dylib you&#039;ve added to your project. Apple now has an automated tool to scan your code for private (ie not-approved methods) and will reject your app if it contains private methods.</description>
		<content:encoded><![CDATA[<p>Just remove the libIOKit.A.dylib you&#8217;ve added to your project. Apple now has an automated tool to scan your code for private (ie not-approved methods) and will reject your app if it contains private methods.</p>
]]></content:encoded>
	</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-05 00:24:29 -->
