tag:blogger.com,1999:blog-73698500696196939572024-02-07T03:39:29.079-08:00sanjay patelSanjay Patelhttp://www.blogger.com/profile/14820649584694075173noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-7369850069619693957.post-60039893754238537012012-11-09T03:05:00.003-08:002012-11-09T03:05:27.511-08:00Key Value Observing iOS / KVO<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="background-color: white; border: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">
You can observe changes across different objects/classes. I think the problem is in the options parameter of <code style="background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 1px 5px; vertical-align: baseline;">addObserver:forKeyPath:options:context:</code>.</div>
<div style="background-color: white; border: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">
There are various options for the type of observing you want to do. The <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/KeyValueObserving/Concepts/KVOBasics.html" rel="nofollow" style="background-color: transparent; border: 0px; color: #4a6b82; cursor: pointer; margin: 0px; padding: 0px; text-decoration: initial; vertical-align: baseline;">KVO Guide</a> is a good starting point, but you probably want <code style="background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 1px 5px; vertical-align: baseline;">NSKeyValueObservingOptionNew</code>, which I use in the example below.</div>
<div style="background-color: white; border: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">
First, "name" should be a public property in ClassB.</div>
<div style="background-color: white; border: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">
Second, you probably don't need to add the observer to "b" in <code style="background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 1px 5px; vertical-align: baseline;">viewWillAppear</code> in ClassA, because you don't need to add it everytime the ClassA view is going to appear. You just need to add the observer once, when you create the ClassB view. Once you've added the observer, the<code style="background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 1px 5px; vertical-align: baseline;">observeValueForKeyPath:ofObject:change:context:</code> method will be executed in ClassA, so you can do the update to the ClassA UI from there. You shouldn't need to do anything every time ClassA is about to appear.</div>
<div style="background-color: white; border: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">
In Class A, you should probably create ClassB just before you are going to push ClassB onto the controller stack, presumably in the event handler for some action the user took. Immediately after you create ClassB, add the observer in ClassA with the correct NSKeyValueObservingOption value.</div>
<div style="background-color: white; border: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">
If you just want to be notified whenever the public property "name" in ClassB is changed, then try this:</div>
<div style="background-color: white; border: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">
ClassB</div>
<pre class="default prettyprint prettyprinted" style="background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto;"><code style="border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="lit" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">@interface</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="typ" style="background-color: transparent; border: 0px; color: #2b91af; margin: 0px; padding: 0px; vertical-align: baseline;">ClassB</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="typ" style="background-color: transparent; border: 0px; color: #2b91af; margin: 0px; padding: 0px; vertical-align: baseline;">UIViewController</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">{</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">}</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="lit" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">@property</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">retain</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">)</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="typ" style="background-color: transparent; border: 0px; color: #2b91af; margin: 0px; padding: 0px; vertical-align: baseline;">NSString</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">*</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> name</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">;</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">-</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="kwd" style="background-color: transparent; border: 0px; color: darkblue; margin: 0px; padding: 0px; vertical-align: baseline;">void</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">)</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> aMethodThatModifiesName</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:(</span><span class="typ" style="background-color: transparent; border: 0px; color: #2b91af; margin: 0px; padding: 0px; vertical-align: baseline;">NSString</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">*)</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">newName</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">;</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="lit" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">@end</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="lit" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">@implementation</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="typ" style="background-color: transparent; border: 0px; color: #2b91af; margin: 0px; padding: 0px; vertical-align: baseline;">ClassB</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="lit" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">@synthesize</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> name</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">;</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">-</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="kwd" style="background-color: transparent; border: 0px; color: darkblue; margin: 0px; padding: 0px; vertical-align: baseline;">void</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">)</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> aMethodThatModifiesName</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:(</span><span class="typ" style="background-color: transparent; border: 0px; color: #2b91af; margin: 0px; padding: 0px; vertical-align: baseline;">NSString</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">*)</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">newName </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">{</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="com" style="background-color: transparent; border: 0px; color: grey; margin: 0px; padding: 0px; vertical-align: baseline;">// do some stuff</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="kwd" style="background-color: transparent; border: 0px; color: darkblue; margin: 0px; padding: 0px; vertical-align: baseline;">self</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">name </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> newName</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">;</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">}</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="lit" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">@end</span></code></pre>
<div style="background-color: white; border: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">
ClassA</div>
<pre class="default prettyprint prettyprinted" style="background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto;"><code style="border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="lit" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">@interface</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="typ" style="background-color: transparent; border: 0px; color: #2b91af; margin: 0px; padding: 0px; vertical-align: baseline;">ClassA</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="typ" style="background-color: transparent; border: 0px; color: #2b91af; margin: 0px; padding: 0px; vertical-align: baseline;">UIViewController</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">{</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">}</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="lit" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">@property</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">nonatomic</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">,</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> retain</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">)</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="typ" style="background-color: transparent; border: 0px; color: #2b91af; margin: 0px; padding: 0px; vertical-align: baseline;">IBOutlet</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="typ" style="background-color: transparent; border: 0px; color: #2b91af; margin: 0px; padding: 0px; vertical-align: baseline;">UILabel</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">*</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> nameLabel</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">;</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">-</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="typ" style="background-color: transparent; border: 0px; color: #2b91af; margin: 0px; padding: 0px; vertical-align: baseline;">IBAction</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">)</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> someEventHandler</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:(</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">id</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">)</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">sender</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">;</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="lit" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">@end</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="lit" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">@implementation</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="typ" style="background-color: transparent; border: 0px; color: #2b91af; margin: 0px; padding: 0px; vertical-align: baseline;">ClassA</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">-</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="typ" style="background-color: transparent; border: 0px; color: #2b91af; margin: 0px; padding: 0px; vertical-align: baseline;">IBAction</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">)</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> someEventHandler</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:(</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">id</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">)</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">sender </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">{</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="typ" style="background-color: transparent; border: 0px; color: #2b91af; margin: 0px; padding: 0px; vertical-align: baseline;">ClassB</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">*</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> b </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">[[</span><span class="typ" style="background-color: transparent; border: 0px; color: #2b91af; margin: 0px; padding: 0px; vertical-align: baseline;">ClassB</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> alloc</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">]</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">init</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">];</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">[</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">b addObserver</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:</span><span class="kwd" style="background-color: transparent; border: 0px; color: darkblue; margin: 0px; padding: 0px; vertical-align: baseline;">self</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> forKeyPath</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:@</span><span class="str" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">"name"</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> options</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:</span><span class="typ" style="background-color: transparent; border: 0px; color: #2b91af; margin: 0px; padding: 0px; vertical-align: baseline;">NSKeyValueObservingOptionNew</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> context</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">NULL</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">];</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">[</span><span class="kwd" style="background-color: transparent; border: 0px; color: darkblue; margin: 0px; padding: 0px; vertical-align: baseline;">self</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">navigationController pushViewController</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">b animated</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">YES</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">];</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">[</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">b release</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">];</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">}</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">-</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="kwd" style="background-color: transparent; border: 0px; color: darkblue; margin: 0px; padding: 0px; vertical-align: baseline;">void</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">)</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> observeValueForKeyPath</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:(</span><span class="typ" style="background-color: transparent; border: 0px; color: #2b91af; margin: 0px; padding: 0px; vertical-align: baseline;">NSString</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">*)</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">keyPath ofObject</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:(</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">id</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">)</span><span class="kwd" style="background-color: transparent; border: 0px; color: darkblue; margin: 0px; padding: 0px; vertical-align: baseline;">object</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> change</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:(</span><span class="typ" style="background-color: transparent; border: 0px; color: #2b91af; margin: 0px; padding: 0px; vertical-align: baseline;">NSDictionary</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">*)</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">change context</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:(</span><span class="kwd" style="background-color: transparent; border: 0px; color: darkblue; margin: 0px; padding: 0px; vertical-align: baseline;">void</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">*)</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">context </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">{</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="kwd" style="background-color: transparent; border: 0px; color: darkblue; margin: 0px; padding: 0px; vertical-align: baseline;">if</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">([</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">keyPath isEqual</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:@</span><span class="str" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">"name"</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">])</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">{</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="typ" style="background-color: transparent; border: 0px; color: #2b91af; margin: 0px; padding: 0px; vertical-align: baseline;">NSString</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">*</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> changedName </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">[</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">change objectForKey</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">:</span><span class="typ" style="background-color: transparent; border: 0px; color: #2b91af; margin: 0px; padding: 0px; vertical-align: baseline;">NSKeyValueChangeNewKey</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">];</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="com" style="background-color: transparent; border: 0px; color: grey; margin: 0px; padding: 0px; vertical-align: baseline;">// do something with the changedName - call a method or update the UI here</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="kwd" style="background-color: transparent; border: 0px; color: darkblue; margin: 0px; padding: 0px; vertical-align: baseline;">self</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">nameLabel</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">text </span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;"> changedName</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">;</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">}</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">}</span><span class="pln" style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="lit" style="background-color: transparent; border: 0px; color: maroon; margin: 0px; padding: 0px; vertical-align: baseline;">@end</span></code></pre>
</div>
Sanjay Patelhttp://www.blogger.com/profile/14820649584694075173noreply@blogger.com0tag:blogger.com,1999:blog-7369850069619693957.post-53556100552780513832012-11-09T02:47:00.001-08:002012-11-09T02:48:01.251-08:00Difference between Notification and Delegate or Delegation / Notification<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="background-color: #f8f8f8; border: 0px; color: #222222; font-family: Helvetica, sans-serif; font-size: 16px; font: inherit; line-height: 28.796875px; margin-bottom: 1.5em; padding: 0px; vertical-align: baseline;">
Is it generally considered best practise to reduce the coupling or dependencies between classes in your application. A key benefit is that your code becomes easier to maintain since a change in one class is less likely to impact another dependent class. It also becomes easier to reuse classes across applications.</div>
<div style="background-color: #f8f8f8; border: 0px; color: #222222; font-family: Helvetica, sans-serif; font-size: 16px; font: inherit; line-height: 28.796875px; margin-bottom: 1.5em; padding: 0px; vertical-align: baseline;">
Cocoa implements a number of features such as delegates and notifications that make this easier to achieve though it can be confusing at first to know when you should use one or the other (or both) or these techniques.</div>
<h3 style="background-color: #f8f8f8; border: 0px; color: #222222; font-family: Helvetica, sans-serif; font-size: 1.3em; font-weight: normal; font: inherit; line-height: 28.796875px; margin: 0px 0px 1em; padding: 0px; text-rendering: optimizelegibility; vertical-align: baseline;">
Delegation</h3>
<div style="background-color: #f8f8f8; border: 0px; color: #222222; font-family: Helvetica, sans-serif; font-size: 16px; font: inherit; line-height: 28.796875px; margin-bottom: 1.5em; padding: 0px; vertical-align: baseline;">
The <a href="http://developer.apple.com/iphone/library/documentation/General/Conceptual/DevPedia-CocoaCore/Delegation.html" style="-webkit-transition: color 0.3s; border: 0px; color: #5187ae; font-size: 16px; font: inherit; margin: 0px; padding: 0px; text-decoration: initial; vertical-align: baseline; white-space: pre-wrap; word-wrap: break-word;">concept of delegation</a> as its name suggests allows an object to send a message to another object (the delegate) so that it can customise the handling of an event. The UITableViewController provides a common example of this in an iPhone application. The delegate of the UITableViewController is informed when a user <em style="border: 0px; font-size: 16px; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">will</em> do something such as select a row allowing the delegate to prevent or change the action. A further call is made to the delegate when the user <em style="border: 0px; font-size: 16px; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">did</em> do something allowing the delegate to take further action such as saving data or triggering the update of a view.</div>
<div style="background-color: #f8f8f8; border: 0px; color: #222222; font-family: Helvetica, sans-serif; font-size: 16px; font: inherit; line-height: 28.796875px; margin-bottom: 1.5em; padding: 0px; vertical-align: baseline;">
The important point about delegation is the way it is implemented allows for minimal dependency between the delegating object and its delegate. The delegating object needs to have a reference to its delegate so that it can call methods in the delegate. However this reference is declared using the anonymous id type:</div>
<pre style="-webkit-box-shadow: rgba(0, 0, 0, 0.0588235) 0px 0px 10px; background-color: #fdf6e3; background-image: url(http://useyourloaf.com/images/noise.png?1337714123); background-position: 0% 0%; border-bottom-left-radius: 0.4em; border-bottom-right-radius: 0.4em; border-top-left-radius: 0.4em; border-top-right-radius: 0.4em; border: 1px solid rgb(231, 222, 195); box-shadow: rgba(0, 0, 0, 0.0588235) 0px 0px 10px; color: #586e75; font-family: Courier, monospace; font-size: 13px; font: inherit; line-height: 1.45em; margin-bottom: 2.1em; overflow: auto; padding: 0.8em 1em; vertical-align: baseline;"><code style="border: 0px; font-family: Courier, monospace; font-size: 13px; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">id delegate;
</code></pre>
<div style="background-color: #f8f8f8; border: 0px; color: #222222; font-family: Helvetica, sans-serif; font-size: 16px; font: inherit; line-height: 28.796875px; margin-bottom: 1.5em; padding: 0px; vertical-align: baseline;">
This way the delegating object does not need to know the type of its delegate which removes a big potential dependency between the classes. This weak reference between the two classes means that the compiler cannot verify that a delegate class actually implements the methods expected by the delegating object.</div>
<div style="background-color: #f8f8f8; border: 0px; color: #222222; font-family: Helvetica, sans-serif; font-size: 16px; font: inherit; line-height: 28.796875px; margin-bottom: 1.5em; padding: 0px; vertical-align: baseline;">
To avoid unexpected runtime exceptions a delegating object can test if a delegate responds to a certain message before invoking it:</div>
<pre style="-webkit-box-shadow: rgba(0, 0, 0, 0.0588235) 0px 0px 10px; background-color: #fdf6e3; background-image: url(http://useyourloaf.com/images/noise.png?1337714123); background-position: 0% 0%; border-bottom-left-radius: 0.4em; border-bottom-right-radius: 0.4em; border-top-left-radius: 0.4em; border-top-right-radius: 0.4em; border: 1px solid rgb(231, 222, 195); box-shadow: rgba(0, 0, 0, 0.0588235) 0px 0px 10px; color: #586e75; font-family: Courier, monospace; font-size: 13px; font: inherit; line-height: 1.45em; margin-bottom: 2.1em; overflow: auto; padding: 0.8em 1em; vertical-align: baseline;"><code style="border: 0px; font-family: Courier, monospace; font-size: 13px; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">if ([delegate respondsToSelector:@selector(myMethod)]) {
[delegate myMethod];
}
</code></pre>
<div style="background-color: #f8f8f8; border: 0px; color: #222222; font-family: Helvetica, sans-serif; font-size: 16px; font: inherit; line-height: 28.796875px; margin-bottom: 1.5em; padding: 0px; vertical-align: baseline;">
This allows a delegate to optionally implement some methods. The ability to specify some delegate methods as mandatory or optional can be formally defined (and checked at compile time) through the use of protocols. There is an example on using delegates with protocols in the post on <a href="http://useyourloaf.com/blog/2010/05/03/ipad-modal-view-controllers.html" style="-webkit-transition: color 0.3s; border: 0px; color: #5187ae; font-size: 16px; font: inherit; margin: 0px; padding: 0px; text-decoration: initial; vertical-align: baseline; white-space: pre-wrap; word-wrap: break-word;">iPad Modal View Controllers</a> so I will skip ahead to the sending and receiving of notifications.</div>
<h3 style="background-color: #f8f8f8; border: 0px; color: #222222; font-family: Helvetica, sans-serif; font-size: 1.3em; font-weight: normal; font: inherit; line-height: 28.796875px; margin: 0px 0px 1em; padding: 0px; text-rendering: optimizelegibility; vertical-align: baseline;">
Notification</h3>
<div style="background-color: #f8f8f8; border: 0px; color: #222222; font-family: Helvetica, sans-serif; font-size: 16px; font: inherit; line-height: 28.796875px; margin-bottom: 1.5em; padding: 0px; vertical-align: baseline;">
The <a href="http://developer.apple.com/iphone/library/documentation/General/Conceptual/DevPedia-CocoaCore/Notification.html" style="-webkit-transition: color 0.3s; border: 0px; color: #5187ae; font-size: 16px; font: inherit; margin: 0px; padding: 0px; text-decoration: initial; vertical-align: baseline; white-space: pre-wrap; word-wrap: break-word;">concept of notification</a> differs from delegation in that it allows a message to be sent to more than one object. It is more like a broadcast rather than a straight communication between two objects. It removes dependencies between the sending and receiving object(s) by using a notification center to manage the sending and receiving of notifications. The sender does not need to know if there are any receivers registered with the notification center. There can be one, many or even no receivers of the notification registered with the notification center.</div>
<div style="background-color: #f8f8f8; border: 0px; color: #222222; font-family: Helvetica, sans-serif; font-size: 16px; font: inherit; line-height: 28.796875px; margin-bottom: 1.5em; padding: 0px; vertical-align: baseline;">
The other difference between notifications and delegates is that there is no possibility for the receiver of a notification to return a value to the sender. Remember the earlier example of a delegate method indicating that a user will select a row in a table. The delegate has the opportunity to return a value which prevents the user from selecting a row. If we use a notification to inform another object that the user is selecting a row there is no way to return a value to influence this action.</div>
<div style="background-color: #f8f8f8; border: 0px; color: #222222; font-family: Helvetica, sans-serif; font-size: 16px; font: inherit; line-height: 28.796875px; margin-bottom: 1.5em; padding: 0px; vertical-align: baseline;">
Typical uses of notifications might be to allow different objects with an application to be informed of an event such as a file download completing or a user changing an application preference. The receiver of the notification might then perform additional actions such as processing the downloaded file or updating the display.</div>
<h3 style="background-color: #f8f8f8; border: 0px; color: #222222; font-family: Helvetica, sans-serif; font-size: 1.3em; font-weight: normal; font: inherit; line-height: 28.796875px; margin: 0px 0px 1em; padding: 0px; text-rendering: optimizelegibility; vertical-align: baseline;">
The Default Notification Center</h3>
<div style="background-color: #f8f8f8; border: 0px; color: #222222; font-family: Helvetica, sans-serif; font-size: 16px; font: inherit; line-height: 28.796875px; margin-bottom: 1.5em; padding: 0px; vertical-align: baseline;">
Cocoa allows you to create multiple notification centers but in practise on the iPhone you will probably only ever need to use the default notification center. You access this default notification center using a class method as follows:</div>
<pre style="-webkit-box-shadow: rgba(0, 0, 0, 0.0588235) 0px 0px 10px; background-color: #fdf6e3; background-image: url(http://useyourloaf.com/images/noise.png?1337714123); background-position: 0% 0%; border-bottom-left-radius: 0.4em; border-bottom-right-radius: 0.4em; border-top-left-radius: 0.4em; border-top-right-radius: 0.4em; border: 1px solid rgb(231, 222, 195); box-shadow: rgba(0, 0, 0, 0.0588235) 0px 0px 10px; color: #586e75; font-family: Courier, monospace; font-size: 13px; font: inherit; line-height: 1.45em; margin-bottom: 2.1em; overflow: auto; padding: 0.8em 1em; vertical-align: baseline;"><code style="border: 0px; font-family: Courier, monospace; font-size: 13px; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
</code></pre>
<h3 style="background-color: #f8f8f8; border: 0px; color: #222222; font-family: Helvetica, sans-serif; font-size: 1.3em; font-weight: normal; font: inherit; line-height: 28.796875px; margin: 0px 0px 1em; padding: 0px; text-rendering: optimizelegibility; vertical-align: baseline;">
Naming a Notification</h3>
<div style="background-color: #f8f8f8; border: 0px; color: #222222; font-family: Helvetica, sans-serif; font-size: 16px; font: inherit; line-height: 28.796875px; margin-bottom: 1.5em; padding: 0px; vertical-align: baseline;">
A notification consists of a name, an object and an optional dictionary to contain user information. The name is used to identify the notification so you should try to choose something unique to your application. Using a two or three letter prefix specific to your application is a good way to do this. Apple also recommends that you define the name as a global constant string variable rather than using the hard coded string value in your code. If you look at the way Apple defines notification names you will also see the name often follows the pattern </div>
</div>
Sanjay Patelhttp://www.blogger.com/profile/14820649584694075173noreply@blogger.com0tag:blogger.com,1999:blog-7369850069619693957.post-56261589992440483642012-10-19T03:37:00.002-07:002012-10-19T03:37:34.275-07:00Extending PhoneGap with native plugins for iOS<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="text parbase section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="Semantic LayoutCellSides LayoutBreakAfter TextMedium" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; min-height: 0px; outline: 0px; padding: 0px 11px;">
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
This article examines native plugins for PhoneGap (also known as Apache Cordova) applications in Xcode, targeting iOS devices. If you are just starting out with PhoneGap or if you need to review the fundamentals of PhoneGap, read<a href="http://www.adobe.com/devnet/html5/articles/getting-started-with-phonegap-in-xcode-for-ios.html" style="border: 0px; color: #627282; cursor: pointer; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-decoration: initial;">Getting started with PhoneGap in Xcode for iOS</a> before continuing.</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
The terms <i>Cordova</i> and <i>PhoneGap</i> are used interchangeably within this article to refer to the same open source application platform that lets you create natively-installed mobile applications using HTML and JavaScript. The PhoneGap codebase moved to open source at Apache Software Foundation under the name Cordova. Adobe is still distributing it under the name PhoneGap. For more information, check out Brian Leroux's blog post "<a href="http://phonegap.com/2012/03/19/phonegap-cordova-and-what%E2%80%99s-in-a-name/" style="border: 0px; color: #627282; cursor: pointer; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-decoration: initial;" target="_blank">PhoneGap, Cordova, and what's in a name?</a>" As Brian says in the post, "Currently, the only difference is in the name of the download package and will remain so for some time."</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
Not only does PhoneGap enable you to build user interfaces for natively installed mobile applications using web technologies, PhoneGap also provides a JavaScript-based API to interact with native device functionality. By default, PhoneGap provides access to the device camera, accelerometer, file system, GPS location, and media playback among other capabilities. However, PhoneGap does not expose every native API for use within your JavaScript applications. If you want PhoneGap to do more than its default feature set, you can use the PhoneGap native plugin model to extend the capabilities of the core PhoneGap API.</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
Native plugins in PhoneGap are not like plugins in desktop browsers; rather they provide a way for you to <i>plug in</i>custom code to add to what the PhoneGap application framework can do. PhoneGap native plugins enable you to create completely new, custom functionality in native code, and expose that to your PhoneGap applications via PhoneGap's native-to-JavaScript bridge. This means that you can expose any native library or framework for use within your JavaScript-based PhoneGap applications.</div>
</div>
</div>
<a href="" name="articlecontentAdobe_numberedheader" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="parbase compbase numberedheader section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<h3 class="TextH3 LayoutCellSides LayoutRow" style="border: 0px; font-family: inherit; font-size: 18px; line-height: 21px; margin: 9px 0px; outline: 0px; padding: 0px 11px;">
Understanding the PhoneGap native plugin structure</h3>
</div>
<a href="" name="articlecontentAdobe_text_0" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="text parbase section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="Semantic LayoutCellSides LayoutBreakAfter TextMedium" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; min-height: 0px; outline: 0px; padding: 0px 11px;">
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
Before you start to write PhoneGap native plugins, it will help to understand how the PhoneGap application container exposes native operating system functionality to JavaScript-based applications.</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
All Cordova APIs consist of two related parts: a JavaScript-based interface that can be accessed within your applications, and the corresponding native class for performing operations in native code. Typically, the JavaScript classes and the native classes have APIs that mirrors each other, so that they are easy to follow. The JavaScript class invokes the native code using the <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">Cordova.exec()</code> function. When it invokes <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">Cordova.exec</code> , it can pass in a result handler function, an error handler function, and an array of parameters to be passed into native code, as well as a reference to the native class's name and native function name. Cordova will manage the JavaScript-to-native communication, and you can focus on building your application.</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
To learn more about PhoneGap native plugins, take a look at the core API's source code, available at the <a href="http://wiki.apache.org/cordova/ContributerWorkflow" style="border: 0px; color: #627282; cursor: pointer; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-decoration: initial;" target="_blank">Cordova wiki</a>. The entire PhoneGap framework is built upon the same paradigm you'll find there.</div>
</div>
</div>
<a href="" name="articlecontentAdobe_numberedheader_0" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="parbase compbase numberedheader section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<h3 class="TextH3 LayoutCellSides LayoutRow" style="border: 0px; font-family: inherit; font-size: 18px; line-height: 21px; margin: 9px 0px; outline: 0px; padding: 0px 11px;">
Building your first plugin</h3>
</div>
<a href="" name="articlecontentAdobe_text_1" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="text parbase section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="Semantic LayoutCellSides LayoutBreakAfter TextMedium" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; min-height: 0px; outline: 0px; padding: 0px 11px;">
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
To start building your first PhoneGap native plugin, you'll need to create a new PhoneGap project following the steps outlined in the article <a href="http://www.adobe.com/devnet/html5/articles/getting-started-with-phonegap-in-xcode-for-ios.html" style="border: 0px; color: #627282; cursor: pointer; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-decoration: initial;">Getting started with PhoneGap in Xcode for iOS</a>. I named my project MyFirstPhoneGapNativePlugin.</div>
<h4 style="border: 0px; font-family: inherit; font-style: inherit; margin: 18px 0px -16px; outline: 0px; padding: 0px;">
The JavaScript class</h4>
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
Once you have set up your <a href="http://www.adobe.com/devnet/html5/articles/getting-started-with-phonegap-in-xcode-for-ios.html" style="border: 0px; color: #627282; cursor: pointer; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-decoration: initial;">Hello Xcode project</a>, you're ready to create the JavaScript interface for the native plugin. You will need to create a class with functions that will mirror the logic exposed by the native code. Under the www folder, create a JavaScript file named HelloPlugin.js that contains the simple JavaScript class shown below.</div>
</div>
</div>
<a href="" name="articlecontentAdobe_codeblock" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="parbase codeblock compbase section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="PanelFillLight PanelBevelTop LayoutCell LayoutRow" style="-webkit-box-shadow: rgba(0, 0, 0, 0.14902) 0px 1px 0px 0px inset; background-color: whitesmoke; border: 0px; box-shadow: rgba(0, 0, 0, 0.14902) 0px 1px 0px 0px inset; font-family: inherit; font-style: inherit; margin: 9px 0px; outline: 0px; padding: 9px 11px;">
<code class="CodeBlock" style="border: 0px; color: black; display: block; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; overflow-x: auto; overflow-y: visible; padding: 12px 0px; white-space: pre;">var HelloPlugin = {
callNativeFunction: function (success, fail, resultType) {
return Cordova.exec( success, fail,
"com.tricedesigns.HelloPlugin",
"nativeFunction",
[resultType]);
}
};
</code></div>
</div>
<a href="" name="articlecontentAdobe_text_2" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="text parbase section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="Semantic LayoutCellSides LayoutBreakAfter TextMedium" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; min-height: 0px; outline: 0px; padding: 0px 11px;">
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
The HelloPlugin class has a single function named <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">callNativeFunction</code> , which accepts a success callback function, an error callback function, and a <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">resultType</code> string parameter. The <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">callNativeFunction</code> function wraps the <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">Cordova.exec</code> function, which will invoke the actual native code. There is no additional JavaScript inside of this class, but you can add JavaScript code here if you need to.</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
When <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">Cordova.exec</code> is invoked, it expects five parameters:</div>
<ul style="border: 0px; font-family: inherit; font-style: inherit; list-style-image: initial; list-style-position: outside; margin: 18px 0px 18px 24px; outline: 0px; padding: 0px;">
<li style="border: 0px; font-family: inherit; font-style: inherit; margin: 4px 0px; outline: 0px; padding: 0px;">a reference to a success callback function (a function that will be invoked upon a successful response from the native code layer)</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; margin: 4px 0px; outline: 0px; padding: 0px;">an error callback function (a function that will be invoked upon an error response from the native layer)</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; margin: 4px 0px; outline: 0px; padding: 0px;">a string reference to the native code class (I cover this in more detail below)</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; margin: 4px 0px; outline: 0px; padding: 0px;">a string reference to the name of the function that should be invoked</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; margin: 4px 0px; outline: 0px; padding: 0px;">an array of parameters to be passed into the native code</li>
</ul>
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
Keep in mind that code execution between the JavaScript and native code layers is not synchronous, so you'll need to use callback functions and asynchronous coding practices when developing PhoneGap native plugins.</div>
<h4 style="border: 0px; font-family: inherit; font-style: inherit; margin: 18px 0px -16px; outline: 0px; padding: 0px;">
The Native class</h4>
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
To create the native code layer, start by creating a new native Objective-C class that extends the CDVPlugin class from the core Cordova API:</div>
<ol style="border: 0px; font-family: inherit; font-style: inherit; list-style-image: initial; list-style-position: outside; margin: 18px 0px 18px 24px; outline: 0px; padding: 0px;">
<li style="border: 0px; font-family: inherit; font-style: inherit; margin: 4px 0px; outline: 0px; padding: 0px;">Right-click the <kbd style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">Plugins</kbd> directory inside of your PhoneGap project, and select New File (see Figure 1).</li>
</ol>
</div>
</div>
<a href="" name="articlecontentAdobe_image" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="parbase image section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="LayoutRow LayoutCellSides" style="border: 0px; font-family: inherit; font-style: inherit; margin: 9px 0px; outline: 0px; padding: 0px 11px;">
<img alt="Figure 1. Creating the new file. " class="cq-dd-image LayoutImage LayoutRow " src="http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/html5/articles/extending-phonegap-with-native-plugins-for-ios/fig_01.jpg" style="border: 0px; display: block; font-family: inherit; font-style: inherit; margin: 9px 0px; max-width: 100%; outline: 0px; padding: 0px;" title="Figure 1. Creating the new file. " /></div>
<div class="TextSmall LayoutCellSides LayoutRowTop LayoutBigRowBottom" style="border: 0px; font-family: inherit; font-size: 12px; font-style: inherit; line-height: 16px; margin: 9px 0px 20px; outline: 0px; padding: 0px 11px;">
Figure 1. Creating the new file.</div>
</div>
<a href="" name="articlecontentAdobe_text_3" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="text parbase section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="Semantic LayoutCellSides LayoutBreakAfter TextMedium" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; min-height: 0px; outline: 0px; padding: 0px 11px;">
<ol start="2" style="border: 0px; font-family: inherit; font-style: inherit; list-style-image: initial; list-style-position: outside; margin: 18px 0px 18px 24px; outline: 0px; padding: 0px;">
<li style="border: 0px; font-family: inherit; font-style: inherit; margin: 4px 0px; outline: 0px; padding: 0px;">In the New File wizard, select the Objective-C class template and click Next (see Figure 2).</li>
</ol>
</div>
</div>
<a href="" name="articlecontentAdobe_image_0" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="parbase image section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="LayoutRow LayoutCellSides" style="border: 0px; font-family: inherit; font-style: inherit; margin: 9px 0px; outline: 0px; padding: 0px 11px;">
<img alt="Figure 2. Selecting the Object-C class template." class="cq-dd-image LayoutImage LayoutRow " src="http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/html5/articles/extending-phonegap-with-native-plugins-for-ios/fig_02.jpg" style="border: 0px; display: block; font-family: inherit; font-style: inherit; margin: 9px 0px; max-width: 100%; outline: 0px; padding: 0px;" title="Figure 2. Selecting the Object-C class template." /></div>
<div class="TextSmall LayoutCellSides LayoutRowTop LayoutBigRowBottom" style="border: 0px; font-family: inherit; font-size: 12px; font-style: inherit; line-height: 16px; margin: 9px 0px 20px; outline: 0px; padding: 0px 11px;">
Figure 2. Selecting the Object-C class template.</div>
</div>
<a href="" name="articlecontentAdobe_text_4" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="text parbase section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="Semantic LayoutCellSides LayoutBreakAfter TextMedium" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; min-height: 0px; outline: 0px; padding: 0px 11px;">
<ol start="3" style="border: 0px; font-family: inherit; font-style: inherit; list-style-image: initial; list-style-position: outside; margin: 18px 0px 18px 24px; outline: 0px; padding: 0px;">
<li style="border: 0px; font-family: inherit; font-style: inherit; margin: 4px 0px; outline: 0px; padding: 0px;">Type <b>HelloPlugin</b> for the new class name and make the class a subclass of CDVPlugin (see Figure 3).</li>
</ol>
</div>
</div>
<a href="" name="articlecontentAdobe_image_1" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="parbase image section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="LayoutRow LayoutCellSides" style="border: 0px; font-family: inherit; font-style: inherit; margin: 9px 0px; outline: 0px; padding: 0px 11px;">
<img alt="Figure 3. Naming the class." class="cq-dd-image LayoutImage LayoutRow " src="http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/html5/articles/extending-phonegap-with-native-plugins-for-ios/fig_03.jpg" style="border: 0px; display: block; font-family: inherit; font-style: inherit; margin: 9px 0px; max-width: 100%; outline: 0px; padding: 0px;" title="Figure 3. Naming the class." /></div>
<div class="TextSmall LayoutCellSides LayoutRowTop LayoutBigRowBottom" style="border: 0px; font-family: inherit; font-size: 12px; font-style: inherit; line-height: 16px; margin: 9px 0px 20px; outline: 0px; padding: 0px 11px;">
Figure 3. Naming the class.</div>
</div>
<a href="" name="articlecontentAdobe_text_5" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="text parbase section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="Semantic LayoutCellSides LayoutBreakAfter TextMedium" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; min-height: 0px; outline: 0px; padding: 0px 11px;">
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
The CDVPlugin class is the parent class that all Cordova classes must extend. The CDVPlugin class encapsulates all logic necessary for native-JavaScript communication via the PhoneGAP API. The <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">PhoneGap.exec</code> function enables you to invoke functions on this new class. The CDVPlugin class has a core function named <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">writeJavascript</code> , which enables you to invoke JavaScript within the PhoneGap application's web view. All communication in the direction of native to web JavaScript must be done using the <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">writeJavascript</code> function.</div>
<ol start="4" style="border: 0px; font-family: inherit; font-style: inherit; list-style-image: initial; list-style-position: outside; margin: 18px 0px 18px 24px; outline: 0px; padding: 0px;">
<li style="border: 0px; font-family: inherit; font-style: inherit; margin: 4px 0px; outline: 0px; padding: 0px;">Click Next.</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; margin: 4px 0px; outline: 0px; padding: 0px;">When prompted specify a location for the new files (preferably the "Plugins" directory within your Xcode project), and then click Finish to proceed.</li>
</ol>
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
You should see the new header file (.h) and implementation file (.m) in your PhoneGap project (see Figure 4).</div>
</div>
</div>
<a href="" name="articlecontentAdobe_image_2" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="parbase image section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="LayoutRow LayoutCellSides" style="border: 0px; font-family: inherit; font-style: inherit; margin: 9px 0px; outline: 0px; padding: 0px 11px;">
<img alt="Figure 4. The new native class files." class="cq-dd-image LayoutImage LayoutRow " src="http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/html5/articles/extending-phonegap-with-native-plugins-for-ios/fig_04.png" style="border: 0px; display: block; font-family: inherit; font-style: inherit; margin: 9px 0px; max-width: 100%; outline: 0px; padding: 0px;" title="Figure 4. The new native class files." /></div>
<div class="TextSmall LayoutCellSides LayoutRowTop LayoutBigRowBottom" style="border: 0px; font-family: inherit; font-size: 12px; font-style: inherit; line-height: 16px; margin: 9px 0px 20px; outline: 0px; padding: 0px 11px;">
Figure 4. The new native class files.</div>
</div>
<a href="" name="articlecontentAdobe_text_6" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="text parbase section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="Semantic LayoutCellSides LayoutBreakAfter TextMedium" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; min-height: 0px; outline: 0px; padding: 0px 11px;">
<ol start="6" style="border: 0px; font-family: inherit; font-style: inherit; list-style-image: initial; list-style-position: outside; margin: 18px 0px 18px 24px; outline: 0px; padding: 0px;">
<li style="border: 0px; font-family: inherit; font-style: inherit; margin: 4px 0px; outline: 0px; padding: 0px;">Next, add a definition for the <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">nativeFunction</code> function in your .h file; for example:</li>
</ol>
</div>
</div>
<a href="" name="articlecontentAdobe_codeblock_0" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="parbase codeblock compbase section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="PanelFillLight PanelBevelTop LayoutCell LayoutRow" style="-webkit-box-shadow: rgba(0, 0, 0, 0.14902) 0px 1px 0px 0px inset; background-color: whitesmoke; border: 0px; box-shadow: rgba(0, 0, 0, 0.14902) 0px 1px 0px 0px inset; font-family: inherit; font-style: inherit; margin: 9px 0px; outline: 0px; padding: 9px 11px;">
<code class="CodeBlock" style="border: 0px; color: black; display: block; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; overflow-x: auto; overflow-y: visible; padding: 12px 0px; white-space: pre;">#import <Cordova/CDV.h>
@interface HelloPlugin : CDVPlugin
- (void) nativeFunction:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
@end
</code></div>
</div>
<a href="" name="articlecontentAdobe_text_7" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="text parbase section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="Semantic LayoutCellSides LayoutBreakAfter TextMedium" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; min-height: 0px; outline: 0px; padding: 0px 11px;">
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
This definition has two parameters: an <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">NSMutableArray</code> of arguments received from the JavaScript layer and a dictionary (map) of options. For this example, you only need to worry about the array of arguments. The header file only contains method signatures; you do not include any application logic in the .h file.</div>
<ol start="7" style="border: 0px; font-family: inherit; font-style: inherit; list-style-image: initial; list-style-position: outside; margin: 18px 0px 18px 24px; outline: 0px; padding: 0px;">
<li style="border: 0px; font-family: inherit; font-style: inherit; margin: 4px 0px; outline: 0px; padding: 0px;">Once you've created your class signature, add your logic to the <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">nativeFunction</code> function instance in the .m file. Below you will see a sample Objective-C function used inside of this native plugin class.</li>
</ol>
</div>
</div>
<a href="" name="articlecontentAdobe_codeblock_1" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="parbase codeblock compbase section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="PanelFillLight PanelBevelTop LayoutCell LayoutRow" style="-webkit-box-shadow: rgba(0, 0, 0, 0.14902) 0px 1px 0px 0px inset; background-color: whitesmoke; border: 0px; box-shadow: rgba(0, 0, 0, 0.14902) 0px 1px 0px 0px inset; font-family: inherit; font-style: inherit; margin: 9px 0px; outline: 0px; padding: 9px 11px;">
<code class="CodeBlock" style="border: 0px; color: black; display: block; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; overflow-x: auto; overflow-y: visible; padding: 12px 0px; white-space: pre;">#import "HelloPlugin.h"
@implementation HelloPlugin
- (void) nativeFunction:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
//get the callback id
NSString *callbackId = [arguments pop];
NSLog(@"Hello, this is a native function called from PhoneGap/Cordova!");
NSString *resultType = [arguments objectAtIndex:0];
CDVPluginResult *result;
if ( [resultType isEqualToString:@"success"] ) {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: @"Success :)"];
[self writeJavascript:[result toSuccessCallbackString:callbackId]];
}
else {
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString: @"Error :("];
[self writeJavascript:[result toErrorCallbackString:callbackId]];
}
}
@end
</code></div>
</div>
<a href="" name="articlecontentAdobe_text_8" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="text parbase section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="Semantic LayoutCellSides LayoutBreakAfter TextMedium" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; min-height: 0px; outline: 0px; padding: 0px 11px;">
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
Inside of the <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">nativeFunction</code> method, you first need to get a reference to the NSString <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">callbackId</code> , which is used by the core PhoneGap API to map the response of this function back to the originating JavaScript that invoked this function.</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
Next this method writes a message out to the Xcode debug console using <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">NSLog</code> ; this just shows that it is executing native code.</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
After writing to the debug console, the function examines the <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">resultType</code> that was passed into the function, and creates the appropriate <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">CDVPluginResult</code> instance. The <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">resultType</code> value is a simple string. If <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">resultType</code> is "<code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">success"</code> , the function will create a <i>success</i> result, and write the success callback to the JavaScript layer using the<code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">[self writeJavascript]</code> function. Any other value for the <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">resultType</code> parameter will generate an <i>error</i> result, and the function will write the error callback to the JavaScript layer.</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
When you write back to the success or error callback functions in JavaScript, always use a CDVPluginResult instance. However, you can also use the <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">writeJavascript</code> function to pass any JavaScript string back to the JavaScript layer. This technique can even be used to <i>push</i> data from the native layer to the JavaScript layer in real time.</div>
</div>
</div>
<a href="" name="articlecontentAdobe_numberedheader_1" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="parbase compbase numberedheader section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<h3 class="TextH3 LayoutCellSides LayoutRow" style="border: 0px; font-family: inherit; font-size: 18px; line-height: 21px; margin: 9px 0px; outline: 0px; padding: 0px 11px;">
Invoking the plugin</h3>
</div>
<a href="" name="articlecontentAdobe_text_9" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="text parbase section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="Semantic LayoutCellSides LayoutBreakAfter TextMedium" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; min-height: 0px; outline: 0px; padding: 0px 11px;">
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
Now that you have created a plugin, you can invoke it from within your PhoneGap application.</div>
<ol style="border: 0px; font-family: inherit; font-style: inherit; list-style-image: initial; list-style-position: outside; margin: 18px 0px 18px 24px; outline: 0px; padding: 0px;">
<li style="border: 0px; font-family: inherit; font-style: inherit; margin: 4px 0px; outline: 0px; padding: 0px;">First, you will need to add a reference to the new plugin's JavaScript interface class (HelloPlugin.js). Add a new<code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;"><script></code> tag inside of your index.html file:</li>
</ol>
</div>
</div>
<a href="" name="articlecontentAdobe_codeblock_4" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="parbase codeblock compbase section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="PanelFillLight PanelBevelTop LayoutCell LayoutRow" style="-webkit-box-shadow: rgba(0, 0, 0, 0.14902) 0px 1px 0px 0px inset; background-color: whitesmoke; border: 0px; box-shadow: rgba(0, 0, 0, 0.14902) 0px 1px 0px 0px inset; font-family: inherit; font-style: inherit; margin: 9px 0px; outline: 0px; padding: 9px 11px;">
<code class="CodeBlock" style="border: 0px; color: black; display: block; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; overflow-x: auto; overflow-y: visible; padding: 12px 0px; white-space: pre;"><script type="text/javascript" charset="utf-8" src="HelloPlugin.js"></script></code></div>
</div>
<a href="" name="articlecontentAdobe_text_10" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="text parbase section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="Semantic LayoutCellSides LayoutBreakAfter TextMedium" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; min-height: 0px; outline: 0px; padding: 0px 11px;">
<ol start="2" style="border: 0px; font-family: inherit; font-style: inherit; list-style-image: initial; list-style-position: outside; margin: 18px 0px 18px 24px; outline: 0px; padding: 0px;">
<li style="border: 0px; font-family: inherit; font-style: inherit; margin: 4px 0px; outline: 0px; padding: 0px;">Also after the <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">onDeviceReady()</code> function, add the JavaScript for invoking the native plugin and handling the plugin results. Add JavaScript functions named <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">callNativePlugin</code> , <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">nativePluginResultHandler</code> , and<code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">nativePluginErrorHandler</code> as shown below:</li>
</ol>
</div>
</div>
<a href="" name="articlecontentAdobe_codeblock_2" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="parbase codeblock compbase section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="PanelFillLight PanelBevelTop LayoutCell LayoutRow" style="-webkit-box-shadow: rgba(0, 0, 0, 0.14902) 0px 1px 0px 0px inset; background-color: whitesmoke; border: 0px; box-shadow: rgba(0, 0, 0, 0.14902) 0px 1px 0px 0px inset; font-family: inherit; font-style: inherit; margin: 9px 0px; outline: 0px; padding: 9px 11px;">
<code class="CodeBlock" style="border: 0px; color: black; display: block; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; overflow-x: auto; overflow-y: visible; padding: 12px 0px; white-space: pre;">function callNativePlugin( returnSuccess ) {
HelloPlugin.callNativeFunction( nativePluginResultHandler, nativePluginErrorHandler, returnSuccess );
}
function nativePluginResultHandler (result) {
alert("SUCCESS: \r\n"+result );
}
function nativePluginErrorHandler (error) {
alert("ERROR: \r\n"+error );
}
</code></div>
</div>
<a href="" name="articlecontentAdobe_text_11" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="text parbase section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="Semantic LayoutCellSides LayoutBreakAfter TextMedium" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; min-height: 0px; outline: 0px; padding: 0px 11px;">
<ol start="3" style="border: 0px; font-family: inherit; font-style: inherit; list-style-image: initial; list-style-position: outside; margin: 18px 0px 18px 24px; outline: 0px; padding: 0px;">
<li style="border: 0px; font-family: inherit; font-style: inherit; margin: 4px 0px; outline: 0px; padding: 0px;">The <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">callNativePlugin</code> function will simply call the JavaScript interface of the native plugin class. When it invokes the <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">callNativeFunction</code> method, it passes the callback functions for success and error status received from the native code layer. The <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">nativePluginResultHandler</code> function will be invoked if there is a success callback from the native layer, and the <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">nativePluginErrorHandler</code> function will be invoked upon an error callback from the native layer.</li>
</ol>
<ol start="4" style="border: 0px; font-family: inherit; font-style: inherit; list-style-image: initial; list-style-position: outside; margin: 18px 0px 18px 24px; outline: 0px; padding: 0px;">
<li style="border: 0px; font-family: inherit; font-style: inherit; margin: 4px 0px; outline: 0px; padding: 0px;">Next add two JavaScript buttons as shown in the code below to invoke the plugin.</li>
</ol>
</div>
</div>
<a href="" name="articlecontentAdobe_codeblock_3" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="parbase codeblock compbase section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="PanelFillLight PanelBevelTop LayoutCell LayoutRow" style="-webkit-box-shadow: rgba(0, 0, 0, 0.14902) 0px 1px 0px 0px inset; background-color: whitesmoke; border: 0px; box-shadow: rgba(0, 0, 0, 0.14902) 0px 1px 0px 0px inset; font-family: inherit; font-style: inherit; margin: 9px 0px; outline: 0px; padding: 9px 11px;">
<code class="CodeBlock" style="border: 0px; color: black; display: block; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; overflow-x: auto; overflow-y: visible; padding: 12px 0px; white-space: pre;"><body onload="onBodyLoad()">
<h1>Hey, it's Cordova!</h1>
<button onclick="callNativePlugin('success');">Click to invoke the Native Plugin with an SUCCESS!</button>
<button onclick="callNativePlugin('error');">Click to invoke the Native Plugin with an ERROR!</button>
</body>
</code></div>
</div>
<a href="" name="articlecontentAdobe_text_12" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="text parbase section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="Semantic LayoutCellSides LayoutBreakAfter TextMedium" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; min-height: 0px; outline: 0px; padding: 0px 11px;">
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
When clicked, the first button will invoke the <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">callNativeFunction</code> method with the parameter "success". PhoneGap will then execute native code and invoke a success callback in the JavaScript layer (it will invoke the<code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">nativePluginResultHandler</code> function).</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
When you click the second button, the <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">callNativeFunction</code> method with will be called with the parameter "error". PhoneGap will execute native code and invoke an error callback in the JavaScript layer (it will invoke the<code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">nativePluginErrorHandler</code> function).</div>
<h4 style="border: 0px; font-family: inherit; font-style: inherit; margin: 18px 0px -16px; outline: 0px; padding: 0px;">
Mapping the native code class</h4>
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
At this point you have almost everything wired up and ready to go, but there is still one more step that you have to complete before you will be able to invoke native code from JavaScript.</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
You have to add a mapping so that Cordova can identify your native code class. Remember the string reference that you used to identify the native class when calling <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">Cordova.exec</code>? You need to map that string to the actual class instance in the Cordova.plist file. The Cordova.plist file contains all configuration information for the current Cordova project.</div>
<ol style="border: 0px; font-family: inherit; font-style: inherit; list-style-image: initial; list-style-position: outside; margin: 18px 0px 18px 24px; outline: 0px; padding: 0px;">
<li style="border: 0px; font-family: inherit; font-style: inherit; margin: 4px 0px; outline: 0px; padding: 0px;">In the project navigator, open the <kbd style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">Supporting Files</kbd> folder, and click the file named Cordova.plist.</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; margin: 4px 0px; outline: 0px; padding: 0px;">On the right, scroll down to the Plugins entry and click to expand it.</li>
<li style="border: 0px; font-family: inherit; font-style: inherit; margin: 4px 0px; outline: 0px; padding: 0px;">Add an entry with the key <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">com.tricedesigns.HelloPlugin</code> and the value <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">"HelloPlugin"</code> (see Figure 5), and replace <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">com.tricedesigns</code> with your company identifier. This is the string reference that you used to identify the native class in the third parameter when calling <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">Cordova.exec</code>.</li>
</ol>
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
The <i>key</i> is the unique string reference that is used by <code style="border: 0px; color: black; font-family: 'Courier New', Courier, monospace; font-style: inherit; margin: 0px; outline: 0px; padding: 0px;">PhoneGap.exec</code> to map to the native code class. The <i>value</i> is the name of the actual native class that will be invoked.</div>
<ol start="4" style="border: 0px; font-family: inherit; font-style: inherit; list-style-image: initial; list-style-position: outside; margin: 18px 0px 18px 24px; outline: 0px; padding: 0px;">
<li style="border: 0px; font-family: inherit; font-style: inherit; margin: 4px 0px; outline: 0px; padding: 0px;">Save your changes.</li>
</ol>
</div>
</div>
<a href="" name="articlecontentAdobe_image_3" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="parbase image section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="LayoutRow LayoutCellSides" style="border: 0px; font-family: inherit; font-style: inherit; margin: 9px 0px; outline: 0px; padding: 0px 11px;">
<img alt="Figure 5. Editing Cordova.plist." class="cq-dd-image LayoutImage LayoutRow " src="http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/html5/articles/extending-phonegap-with-native-plugins-for-ios/fig_05.jpg" style="border: 0px; display: block; font-family: inherit; font-style: inherit; margin: 9px 0px; max-width: 100%; outline: 0px; padding: 0px;" title="Figure 5. Editing Cordova.plist." /></div>
<div class="TextSmall LayoutCellSides LayoutRowTop LayoutBigRowBottom" style="border: 0px; font-family: inherit; font-size: 12px; font-style: inherit; line-height: 16px; margin: 9px 0px 20px; outline: 0px; padding: 0px 11px;">
Figure 5. Editing Cordova.plist.</div>
</div>
<a href="" name="articlecontentAdobe_text_13" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="text parbase section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="Semantic LayoutCellSides LayoutBreakAfter TextMedium" style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; min-height: 0px; outline: 0px; padding: 0px 11px;">
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
Now you are ready to launch the application and test it out.</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
To launch the application click the Run button or choose Product > Run.</div>
<div style="border: 0px; font-family: inherit; font-style: inherit; margin-bottom: 18px; margin-top: 18px; outline: 0px; padding: 0px;">
Once the application launches in the iOS Simulator (or on a connected device), you will see a simple interface with two buttons (see Figure 6). Click on either button to invoke the native plugin's native code, and an alert message will be displayed via JavaScript upon either a success or error callback.</div>
</div>
</div>
<a href="" name="articlecontentAdobe_image_4" style="background-color: white; border: 0px; color: #006699; cursor: pointer; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px; visibility: hidden;"></a><div class="parbase image section" style="background-color: white; border: 0px; color: #333333; font-family: myriad-pro-1, myriad-pro-2, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 19px; margin: 0px; outline: 0px; padding: 0px;">
<div class="LayoutRow LayoutCellSides" style="border: 0px; font-family: inherit; font-style: inherit; margin: 9px 0px; outline: 0px; padding: 0px 11px;">
<img alt="Figure 6. The application running in the iOS simulator." class="cq-dd-image LayoutImage LayoutRow " src="http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/html5/articles/extending-phonegap-with-native-plugins-for-ios/fig_06.jpg" style="border: 0px; display: block; font-family: inherit; font-style: inherit; margin: 9px 0px; max-width: 100%; outline: 0px; padding: 0px;" title="Figure 6. The application running in the iOS simulator." /></div>
<div class="TextSmall LayoutCellSides LayoutRowTop LayoutBigRowBottom" style="border: 0px; font-family: inherit; font-size: 12px; font-style: inherit; line-height: 16px; margin: 9px 0px 20px; outline: 0px; padding: 0px 11px;">
Figure 6. The application running in the iOS simulator.</div>
</div>
</div>
Sanjay Patelhttp://www.blogger.com/profile/14820649584694075173noreply@blogger.com0tag:blogger.com,1999:blog-7369850069619693957.post-24880797791877622592012-10-13T04:12:00.001-07:002012-10-13T04:12:07.219-07:00Free To Paid iPhone Application Data Migrations With Custom URL Handlers<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="background-color: rgba(255, 255, 255, 0.952941); border: 0px; color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; margin-bottom: 20px; outline: 0px; padding: 0px; vertical-align: baseline;">
Free stores user data in an <a href="http://www.zetetic.net/software/sqlcipher" style="background-color: transparent; border: 0px; color: #262626; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">encrypted SQLite Database</a>. Since we really wanted a way to copy the data file from Free to paid we developed a fairly clever solution: use a registered <span class="caps" style="background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">URL</span> handler as a means of communication between application versions. This is how it works:</div>
<blockquote style="background-color: rgba(255, 255, 255, 0.952941); background-image: url(http://mobileorchard.com/wp-content/themes/Canvas/images/blockquote.png); background-position: 0px 12px; background-repeat: no-repeat no-repeat; border: 0px; color: #444444; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; margin: 0px; outline: 0px; padding: 10px 20px 10px 50px; quotes: none; vertical-align: baseline;">
<ol style="background-color: transparent; border: 0px; list-style: none; margin: 0px 0px 15px; outline: 0px; padding: 0px 0px 0px 30px; vertical-align: baseline;">
<li style="background-color: transparent; border: 0px; list-style-type: upper-latin; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">A customer downloads free and enters some unique private data. All information is written to a database in the application’s document directory.</li>
<li style="background-color: transparent; border: 0px; list-style-type: upper-latin; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">When the 10 record limit is hit free asks them to upgrade. An upgrade button launches to explain the process and allow the user to download the paid version of the product.</li>
<li style="background-color: transparent; border: 0px; list-style-type: upper-latin; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Once Strip is purchased and installed, our customer will launch free and click an “Export to free” button. free reads the application database into an NSData object, Base64 encodes it and then Launches a “strip://” <span class="caps" style="background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">URL</span> with the encoded file contents as a <span class="caps" style="background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">URL</span> parameter.</li>
<li style="background-color: transparent; border: 0px; list-style-type: upper-latin; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">The full version of paid is registered as a handler for “strip://” URLs. The OS launches paid and passed the <span class="caps" style="background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">URL</span> to the handleOpenURL method of the application delegate. It parses and decodes the data and writes the database to the desired location in the new applications Document folder.</li>
<li style="background-color: transparent; border: 0px; list-style-type: upper-latin; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Our customer now has access to all the data the originally entered into free!</li>
</ol>
</blockquote>
<h3 style="background-color: rgba(255, 255, 255, 0.952941); border: 0px; color: #222222; font-family: Georgia, serif; font-size: 20px; font-weight: normal; line-height: 1.5em; margin: 0px; outline: 0px; padding: 0px 0px 10px; vertical-align: baseline;">
Project Setup</h3>
<div style="background-color: rgba(255, 255, 255, 0.952941); border: 0px; color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; margin-bottom: 20px; outline: 0px; padding: 0px; vertical-align: baseline;">
This tutorial assumes that your project is already configured with two targets, one for your full version, and one for the Lite.</div>
<div style="background-color: rgba(255, 255, 255, 0.952941); border: 0px; color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; margin-bottom: 20px; outline: 0px; padding: 0px; vertical-align: baseline;">
Start by creating a new InfoLite.plist file for your Lite version. We use 2 separate .plist files to ensure that the Full version is the only registered <span class="caps" style="background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">URL</span> handler (we don’t want the Lite version responding to upgrade events itself!). It is easiest to just make a copy of the existing Info.plist file named InfoLite.plist.</div>
<div style="background-color: rgba(255, 255, 255, 0.952941); border: 0px; color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; margin-bottom: 20px; outline: 0px; padding: 0px; vertical-align: baseline;">
Next, Open up the Build preferences for the Lite target. Change the <strong style="background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Info.plist File</strong> property to read InfoLite.plist. This will ensure that the Lite target includes the proper file.</div>
<div style="background-color: rgba(255, 255, 255, 0.952941); border: 0px; color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; margin-bottom: 20px; outline: 0px; padding: 0px; vertical-align: baseline;">
<img src="http://www.mobileorchard.com/wp-content/uploads/2009/06/xcode_build.png" style="background-color: rgba(255, 255, 255, 0.701961); border: 1px solid rgb(217, 217, 217); margin: 0px; outline: 0px; padding: 5px; vertical-align: baseline;" /></div>
<div style="background-color: rgba(255, 255, 255, 0.952941); border: 0px; color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; margin-bottom: 20px; outline: 0px; padding: 0px; vertical-align: baseline;">
Now open the <strong style="background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Info.plist</strong> (used by the Full Version) and register a custom <span class="caps" style="background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">URL</span> handler. This is a straightforward process of adding elements as shown in the following screenshot.</div>
<div style="background-color: rgba(255, 255, 255, 0.952941); border: 0px; color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; margin-bottom: 20px; outline: 0px; padding: 0px; vertical-align: baseline;">
<img src="http://www.mobileorchard.com/wp-content/uploads/2009/06/info_plist.png" style="background-color: rgba(255, 255, 255, 0.701961); border: 1px solid rgb(217, 217, 217); margin: 0px; outline: 0px; padding: 5px; vertical-align: baseline;" /></div>
<div style="background-color: rgba(255, 255, 255, 0.952941); border: 0px; color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; margin-bottom: 20px; outline: 0px; padding: 0px; vertical-align: baseline;">
Please note that the <span class="caps" style="background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">URL</span> identifier and <span class="caps" style="background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">URL</span> scheme must be unique for your application — see this stepwise overview of <a href="http://www.mobileorchard.com/apple-approved-iphone-inter-process-communication/" style="background-color: transparent; border: 0px; color: #262626; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">the process</a> for reference.</div>
<span style="background-color: rgba(255, 255, 255, 0.952941); color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px;">Finally, the application must include code to perform Base64 encoding itself. This functionality is, unfortunately, not directly accessible in the framework</span><span style="background-color: rgba(255, 255, 255, 0.952941); color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px;"> </span><span class="caps" style="border: 0px; color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">SDK</span><span style="background-color: rgba(255, 255, 255, 0.952941); color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px;">. There are a few options in Cocoa, including</span><span style="background-color: rgba(255, 255, 255, 0.952941); color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px;"> </span><a href="http://www.dribin.org/dave/blog/archives/2006/03/12/base64_cocoa/" style="border: 0px; color: #262626; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">using OpenSSL’s libcrypto</a><span style="background-color: rgba(255, 255, 255, 0.952941); color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px;">, but the easiest method is to use the encoding libraries from</span><a href="http://code.google.com/p/google-toolbox-for-mac/" style="border: 0px; color: #262626; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Google Toolbox for Mac</a><span style="background-color: rgba(255, 255, 255, 0.952941); color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px;"> </span><span style="background-color: rgba(255, 255, 255, 0.952941); color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px;">which is conveniently distributed under the Open Source Apache License. Download</span><span style="background-color: rgba(255, 255, 255, 0.952941); color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px;"> </span><a href="http://google-toolbox-for-mac.googlecode.com/svn/trunk/GTMDefines.h" style="border: 0px; color: #262626; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">GTMDefines.h</a><span style="background-color: rgba(255, 255, 255, 0.952941); color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px;">,</span><span style="background-color: rgba(255, 255, 255, 0.952941); color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px;"> </span><a href="http://google-toolbox-for-mac.googlecode.com/svn/trunk/Foundation/GTMBase64.h" style="border: 0px; color: #262626; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">GTMBase64.h</a><span style="background-color: rgba(255, 255, 255, 0.952941); color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px;"> </span><span style="background-color: rgba(255, 255, 255, 0.952941); color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px;">and</span><span style="background-color: rgba(255, 255, 255, 0.952941); color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px;"> </span><a href="http://google-toolbox-for-mac.googlecode.com/svn/trunk/Foundation/GTMBase64.m" style="border: 0px; color: #262626; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">GTMBase64.m</a><span style="background-color: rgba(255, 255, 255, 0.952941); color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px;">, then add them to your project. The</span><span style="background-color: rgba(255, 255, 255, 0.952941); color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px;"> </span><span class="caps" style="border: 0px; color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">GTM</span><span style="background-color: rgba(255, 255, 255, 0.952941); color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px;"> </span><span style="background-color: rgba(255, 255, 255, 0.952941); color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px;">code compiles perfectly on the iPhone and even includes web safe variants that are immediately suitable for use in URLs without percent encoding.</span><br />
<br />
<div style="background-color: rgba(255, 255, 255, 0.952941); border: 0px; color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; margin-bottom: 20px; outline: 0px; padding: 0px; vertical-align: baseline;">
he controller action code will read the data file, encode it and then format a <span class="caps" style="background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">URL</span> with the protocol prefix / <span class="caps" style="background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">URL</span> scheme configured in the previous step.</div>
<pre style="background-color: rgba(255, 255, 255, 0.952941); border: 0px; color: #474747; font-size: 14px; line-height: 21px; outline: 0px; padding: 0px; vertical-align: baseline;">#import "GTMBase64.h"
...
NSData *fileData = [NSData dataWithContentsOfFile:@"/path/to/LiteApplication/Documents/file"];
NSString *encodedString = [GTMBase64 stringByWebSafeEncodingData:fileData padded:YES];
NSString *urlString = [NSString stringWithFormat:@"myapp://localhost/importDatabase?%@", encodedString];
NSURL *openURL = [NSURL URLWithString:urlString];
[[UIApplication sharedApplication] openURL:openURL];
</pre>
<h4 style="background-color: rgba(255, 255, 255, 0.952941); border: 0px; color: #222222; font-family: Georgia, serif; font-size: 16px; font-weight: normal; line-height: 1.5em; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">
The Full Version</h4>
<div style="background-color: rgba(255, 255, 255, 0.952941); border: 0px; color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; margin-bottom: 20px; outline: 0px; padding: 0px; vertical-align: baseline;">
The final step is to make your application handle the Open <span class="caps" style="background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">URL</span> event and reverse the encoding process.</div>
<div style="background-color: rgba(255, 255, 255, 0.952941); border: 0px; color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; margin-bottom: 20px; outline: 0px; padding: 0px; vertical-align: baseline;">
<img src="http://www.mobileorchard.com/wp-content/uploads/2009/06/strip-upgrade.png" style="background-color: rgba(255, 255, 255, 0.701961); border: 1px solid rgb(217, 217, 217); margin: 0px; outline: 0px; padding: 5px; vertical-align: baseline;" /></div>
<div style="background-color: rgba(255, 255, 255, 0.952941); border: 0px; color: #474747; font-family: Arial, sans-serif; font-size: 14px; line-height: 21px; margin-bottom: 20px; outline: 0px; padding: 0px; vertical-align: baseline;">
Add a handleOpenURL method to the AppDelegate implementation as follows. This will receive the <span class="caps" style="background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">URL</span>, sanity check it, and then parse the query string directly. The resulting binary data is written to the file in the full application’s data directory.</div>
<pre style="background-color: rgba(255, 255, 255, 0.952941); border: 0px; color: #474747; font-size: 14px; line-height: 21px; outline: 0px; padding: 0px; vertical-align: baseline;">#import "GTMBase64.h"
...
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
if([@"/importDatabase" isEqual:[url path]]) {
NSString *query = [url query];
NSString *importUrlData = [GTMBase64 webSafeDecodeString:query];
// NOTE: In practice you will want to prompt the user to confirm before you overwrite their files!
[importUrlData writeToFile:@"/path/to/FullApplication/Documents/file" atomically:YES];
return YES;
}
return NO; </pre>
<span style="background-color: rgba(255, 255, 255, 0.952941); color: #474747; font-size: 14px; line-height: 21px;">}</span><br />
</div>
Sanjay Patelhttp://www.blogger.com/profile/14820649584694075173noreply@blogger.com0tag:blogger.com,1999:blog-7369850069619693957.post-5407904959466739662012-10-02T03:36:00.001-07:002012-10-02T03:36:23.393-07:00use single developement profile in different devices<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div style="background-color: white; border: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">
<b><span style="color: red;">Use one iPhone development license on different mac.</span></b></div>
<div style="background-color: white; border: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">
<b><span style="color: red;"><br /></span></b></div>
<div style="background-color: white; border: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">
<strong style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">Step 1:</strong> To export your private key and certificate for safe-keeping and for enabling development on multiple systems, open up the Keychain Access Application and select the ‘Keys’ category.</div>
<div style="background-color: white; border: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">
<strong style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">Step 2:</strong> Control-Click on the private key associated with your iPhone Development Certificate and click ‘Export Items’ in the menu. The private key is identified by the iPhone Developer: public certificate that is paired with it.</div>
<div style="background-color: white; border: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">
<strong style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">Step 3:</strong> Save your key in the Personal Information Exchange (.p12) file format.</div>
<div style="background-color: white; border: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">
<strong style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">Step 4:</strong> You will be prompted to create a password which is used when you attempt to import this key on another computer.</div>
<div style="background-color: white; border: 0px; clear: both; font-family: Arial, 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;">
<strong style="background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;">Step 5:</strong> You can now transfer this .p12 file between systems. Double-click on the .p12 to install it on a system. You will be prompted for the password you entered in Step 4.</div>
</div>
Sanjay Patelhttp://www.blogger.com/profile/14820649584694075173noreply@blogger.com0tag:blogger.com,1999:blog-7369850069619693957.post-75785110367560609112011-06-16T22:24:00.000-07:002011-06-16T22:24:18.592-07:00Refund Paid Apps in Android Market<div dir="ltr" style="text-align: left;" trbidi="on"><span class="Apple-style-span" style="color: #333333; font-family: Verdana, Geneva, sans-serif; font-size: 12px; line-height: 18px;"></span><br />
<h2 style="border-bottom-style: none; border-bottom-width: 1px; border-color: initial; border-color: initial; border-left-style: none; border-left-width: 0px; border-right-style: none; border-right-width: 0px; border-style: initial; border-top-style: none; border-top-width: 0px; border-width: initial; color: #282828; display: block; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 18px; font-style: inherit; font-weight: inherit; margin-bottom: 8px; margin-left: 0px; margin-right: 20px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 5px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Android Apps – Try before your Buy</h2><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; margin-bottom: 20px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Say you have found an interesting app in Google’s Android Market that you are quite willing to buy but as the app price is a bit on the expensive side, you would like to use the app and test the various features before loosening your purse strings.</div><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; margin-bottom: 20px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Google doesn’t offer “try before you buy” apps but there’s an easy workaround that will help you test any paid app before buying it – you buy an app from the Android market, use it for about 10-12 minutes and then refund the app. The app will be uninstalled from your mobile phone and your account won’t be charged.</div><h3 style="border-bottom-style: none; border-bottom-width: 1px; border-color: initial; border-color: initial; border-left-style: none; border-left-width: 0px; border-right-style: none; border-right-width: 0px; border-style: initial; border-top-style: none; border-top-width: 0px; border-width: initial; color: #333333; display: block; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 16px; font-style: inherit; font-weight: inherit; margin-bottom: 8px; margin-left: 0px; margin-right: 20px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 5px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">How to Refund an Android App</h3><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; margin-bottom: 20px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">It take a few easy steps to refund an app to the Android Market:</div><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; margin-bottom: 20px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><a href="http://img.labnol.org/di/SC20110523-124249.png" rel="lightbox" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #000099; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank" title="A: Buy an Android App"><img alt="" height="89" src="http://img.labnol.org/di/SC20110523-1242491.png" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" width="120" /></a> <a href="http://img.labnol.org/di/SC20110523-123852.png" rel="lightbox" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #000099; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank" title="B: Test the App"><img alt="SC20110523-123852" height="89" src="http://img.labnol.org/di/SC20110523-1238521.png" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" width="103" /></a> <a href="http://img.labnol.org/di/SC20110523-124100.png" rel="lightbox" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #000099; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank" title="C: Refund the App"><img alt="" height="89" src="http://img.labnol.org/di/SC20110523-1241001.png" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" width="116" /></a> <a href="http://img.labnol.org/di/SC20110523-124124.png" rel="lightbox" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #000099; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank" title="D: Give a reason"><img alt="" height="89" src="http://img.labnol.org/di/SC20110523-1241241.png" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" width="145" /></a></div><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; margin-bottom: 20px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Step 1: Visit the Google Android Market, either on your desktop or your mobile phone, and buy any of the 'paid' apps.</div><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; margin-bottom: 20px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Step 2: The app is now installed on your mobile phone. Launch the app and you can test it for the next 10-12 minutes.</div><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; margin-bottom: 20px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Step 3. Go back to the Android Market app on your mobile phone and under "My Apps," tap the app name that you are trying to refund. Hit the "Refund" button and the app will automatically uninstall from your mobile phone.</div><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; margin-bottom: 20px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Step 4. Once the App has been uninstalled, it may ask you to specify a reason for removing the app. You can check "I'd rather not say" here and the app amount will be refunded. You’ll also get an email from Google saying:</div><blockquote style="background-attachment: initial; background-clip: initial; background-color: #fefefe; background-image: url(http://digitalinspiration.com/css/quote.gif); background-origin: initial; background-position: 5px 5px; background-repeat: no-repeat no-repeat; border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; margin-bottom: 5px; margin-left: 5px; margin-right: 5px; margin-top: 5px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 1px; padding-left: 35px; padding-right: 5px; padding-top: 5px; quotes: '', '';"><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 2px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">You have uninstalled the application from your phone. We have cancelled your order and you have not been charged.</div></blockquote><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; margin-bottom: 20px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">The refund process is quite easy and 10 minutes are often enough for you to get a good idea about an app. I tried this with at least two different paid apps and the whole thing worked without a hitch. There are however two things regarding Google’s <a href="http://www.google.com/support/androidmarket/bin/answer.py?answer=134336" style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #000099; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-decoration: none;" target="_blank">refund policy</a> that you should know:</div><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; margin-bottom: 20px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">1. You only have 15 minutes to return an app to the Android Market from the time of download after which the “refund” option will disappear from the app.</div><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; color: #333333; font-family: inherit; font-size: 12px; font-style: inherit; font-weight: inherit; margin-bottom: 20px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">2. You can return an app only once; if you refund an app and purchase it again, you won’t be able to refund it to the Android Market.</div></div>Sanjay Patelhttp://www.blogger.com/profile/14820649584694075173noreply@blogger.com0tag:blogger.com,1999:blog-7369850069619693957.post-9913861913531799982011-06-09T03:19:00.000-07:002011-06-09T03:19:09.530-07:00Popup SMS Pro(Android Application)<div dir="ltr" style="text-align: left;" trbidi="on"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiA-xulach6ny0d3ZBIQix4Ci6e9prlM2Vx1HLx3wC30-A_TcK0zIFEixiSC_jsO_9ia0DJQP0TIYvzPYogTqTYXCODe72-4nPiXFfStN9dGLDbS8YiZfLP4Fq45omCh8-sKM1kdMNN_nN/s1600/PopupSMS-icon-V3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiA-xulach6ny0d3ZBIQix4Ci6e9prlM2Vx1HLx3wC30-A_TcK0zIFEixiSC_jsO_9ia0DJQP0TIYvzPYogTqTYXCODe72-4nPiXFfStN9dGLDbS8YiZfLP4Fq45omCh8-sKM1kdMNN_nN/s320/PopupSMS-icon-V3.png" width="320" /></a></div><div class="separator" style="clear: both; text-align: center;"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; color: #666666; font-family: 'Droid Sans', Arial, sans-serif; font-size: 13px; line-height: 19px;"></span></div><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 1em; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><br />
</div><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 1em; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: left;"></div><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 1em; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Popup SMS Pro... is the version with lots of more features ....if you want you can try the Popup SMS and if you feel you require the pro version then go for it the major difference are as follows.</div><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 1em; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Full feature list for Popup SMS pro:<br />
- Convenient popup window on incoming message<br />
- Quickly reply, delete, forward, call or close the message<br />
-Customize notifications including sound, vibrate pattern, LED color (if available).<br />
-Also customize notifications for individual contacts<br />
-Setup notification reminders (repeating notifications if you miss the first one)<br />
-Optional privacy mode to hide sender name and message contents</div><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 1em; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Plus......</div><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 1em; padding-left: 0px; padding-right: 0px; padding-top: 0px;">1. Customized User Interface, that is themes, you can change the button color and Popup Border Color. Check the screen shots for the themes you can make for yourself. Match the theme with your handset and enjoy the app.</div><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 1em; padding-left: 0px; padding-right: 0px; padding-top: 0px;">2. The color picker gives you million color choices to create your theme. Check out the screen shot. You just have select the colors and test the theme and done. Cool!!!!!</div><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 1em; padding-left: 0px; padding-right: 0px; padding-top: 0px;">3. Post to Facebook is one of the cool features, which is integrated in this pro version, if you want to just have the single feature in one app than you can use Social texts application here. but the Popup SMS pro with this feature makes it more convenient way to post your SMS to Facebook, no more SMS charges to send your post to Facebook or no hassles to copy paste the text to update your Facebook status, just a single click and update the status...</div><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 1em; padding-left: 0px; padding-right: 0px; padding-top: 0px;">4. The post to Facebook has a edit box which lets you edit the message before sending it, you can add your tag line or anything to the text before updating it to Facebook.</div><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 1em; padding-left: 0px; padding-right: 0px; padding-top: 0px;">5. Quick reply can let you reply the SMS immediately from the Popup SMS Pro.</div><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 1em; padding-left: 0px; padding-right: 0px; padding-top: 0px;">6. Facebook Login & Logout option... so not to worry if you need change the Facebook Login.</div><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 1em; padding-left: 0px; padding-right: 0px; padding-top: 0px;">7. Many More coming soon.....Provide your inputs by mailing us or by commenting.......Giving us low rating will not help us to improve the features, so please avoid that....</div><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 1em; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: justify;"><br />
</div><div class="separator" style="clear: both; text-align: right;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJnU1Lzi_nh589ZbVYsIwzt_PgLSKpjcPPmiHdfkKWzGT26jkNOKQcJfAqIfWy9fa88ly889RFiyWizGa_GCl6_Y-o24sX7Jr7xney69mTyefpmNRaTXnLKnGP-1_mK6cZ9jMXafY3TwNT/s1600/message.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJnU1Lzi_nh589ZbVYsIwzt_PgLSKpjcPPmiHdfkKWzGT26jkNOKQcJfAqIfWy9fa88ly889RFiyWizGa_GCl6_Y-o24sX7Jr7xney69mTyefpmNRaTXnLKnGP-1_mK6cZ9jMXafY3TwNT/s320/message.png" width="213" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNXoV0RnJ35pqVuDMhGhC_WHcoqhEPJul_O2nZi5v-hghGeMC_54Life8dNVaqZ5k3DxxlvAN74R-Fc6Obi23cVIiiAM6BeJXbQ-Rt9BAFMG0LR9FWNbXuGOFk4n9O2Z3dNJ3i5ucZSxYr/s1600/more.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNXoV0RnJ35pqVuDMhGhC_WHcoqhEPJul_O2nZi5v-hghGeMC_54Life8dNVaqZ5k3DxxlvAN74R-Fc6Obi23cVIiiAM6BeJXbQ-Rt9BAFMG0LR9FWNbXuGOFk4n9O2Z3dNJ3i5ucZSxYr/s320/more.png" width="213" /></a></div><div class="separator" style="clear: both; text-align: right;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGN5QGMtyrdN_R0fu-t-Nrx5h3N-FTj1Dh1fhLrksv9E9GedyLgnfCrCaTtEPBhZasqv5CEGhQzWcQH9sTZ4omdwWHPPcO4JvGHMPWOs2USIC89zvCOYFhzU2Nf1O8z-XDxFVaYsSNbUUo/s1600/fb+login.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGN5QGMtyrdN_R0fu-t-Nrx5h3N-FTj1Dh1fhLrksv9E9GedyLgnfCrCaTtEPBhZasqv5CEGhQzWcQH9sTZ4omdwWHPPcO4JvGHMPWOs2USIC89zvCOYFhzU2Nf1O8z-XDxFVaYsSNbUUo/s320/fb+login.png" width="213" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiQRLdu5G5PiqM_SAKbdPQCEN5QrDsTPscoiN0Gg_RVUNA43VRji9TC3rHH5o3N7MOauS_6vytBNSbuPqavYlrdsFSxvt3O0KD_RPAoS8LLpCCzdVWxsolfKixRYtYtS-zzWDFYyYM7i_o/s1600/edit+mess.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhiQRLdu5G5PiqM_SAKbdPQCEN5QrDsTPscoiN0Gg_RVUNA43VRji9TC3rHH5o3N7MOauS_6vytBNSbuPqavYlrdsFSxvt3O0KD_RPAoS8LLpCCzdVWxsolfKixRYtYtS-zzWDFYyYM7i_o/s320/edit+mess.png" width="213" /></a></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTEtFMAPTiIl66DFnrLl06ublw6N0j3Qy-HSvFj2LZv5dFkRCsRe3EYo5il8mZZLR81M1qvaGAawofpRPJHghjv_bOw_xTHTL8XjNVJm1SYyAUWVAIaNgopFf8YPr6ejXI1yzqfx5epKNe/s1600/Quick+Reply.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em; text-align: left;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTEtFMAPTiIl66DFnrLl06ublw6N0j3Qy-HSvFj2LZv5dFkRCsRe3EYo5il8mZZLR81M1qvaGAawofpRPJHghjv_bOw_xTHTL8XjNVJm1SYyAUWVAIaNgopFf8YPr6ejXI1yzqfx5epKNe/s320/Quick+Reply.png" width="213" /></a></div><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAT3ex89oI_CRKXiOQYuA8ABOImtiJiHiFc1Y8zuE0y9J9CPS6WPurUQG6RP_5SzvmfX5l0QIRUWk-ngdmvpSWAfTK0uNOKudu8DmVXpDfc-LwsWZUs3FfjeUycXSzht6IgHZREdh_v6h9/s1600/setting.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAT3ex89oI_CRKXiOQYuA8ABOImtiJiHiFc1Y8zuE0y9J9CPS6WPurUQG6RP_5SzvmfX5l0QIRUWk-ngdmvpSWAfTK0uNOKudu8DmVXpDfc-LwsWZUs3FfjeUycXSzht6IgHZREdh_v6h9/s320/setting.png" width="213" /></a><br />
<div class="separator" style="clear: both; text-align: right;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiR3ZLOu9SmhB-9wV4GWYreKCbKtqVRFAL006cpZISXz3sSrWY-xUjqgOv5XwRaLyHWoT6jVU5tfcYGG5b0IdlsxjQsl_YXQ45-HjWNiygoC0GvWGYLVj8mfeKO5m6BuN8_N9onK-ioZL3g/s1600/theme+color.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiR3ZLOu9SmhB-9wV4GWYreKCbKtqVRFAL006cpZISXz3sSrWY-xUjqgOv5XwRaLyHWoT6jVU5tfcYGG5b0IdlsxjQsl_YXQ45-HjWNiygoC0GvWGYLVj8mfeKO5m6BuN8_N9onK-ioZL3g/s320/theme+color.png" width="213" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHs4zLfTG9Cagxb-miIj8hqXj6GyKASq4RhY21FBvuc2DZTqUhIRq4mI-bmuxxgdtH1pZHVECW4-XLm6tGH4MvplT9DzO7Omxy7QkuxMPX9PyIJOIqw8ED2_-TUbIZHf8Jahey-k8xOaQN/s1600/pick+color.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHs4zLfTG9Cagxb-miIj8hqXj6GyKASq4RhY21FBvuc2DZTqUhIRq4mI-bmuxxgdtH1pZHVECW4-XLm6tGH4MvplT9DzO7Omxy7QkuxMPX9PyIJOIqw8ED2_-TUbIZHf8Jahey-k8xOaQN/s320/pick+color.png" width="213" /></a></div><div class="separator" style="clear: both; text-align: left;"></div><div class="" style="clear: both; text-align: left;"> </div><div class="separator" style="clear: both; text-align: left;"><br />
</div><div class="separator" style="clear: both; text-align: left;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYGgBh0KUZH7B9AyEfo7n40EKIMmW8rSvHfzFl7RITkM4-iUuyNPLmQ2XEQSoNHZEDYTwIc16Cp8Ca4wiu9dLk0R5G3CRgWgpLufsxJa5_eQ58q64SWoPODusvhd0JEE8DSTu8udJa0221/s1600/theme2.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYGgBh0KUZH7B9AyEfo7n40EKIMmW8rSvHfzFl7RITkM4-iUuyNPLmQ2XEQSoNHZEDYTwIc16Cp8Ca4wiu9dLk0R5G3CRgWgpLufsxJa5_eQ58q64SWoPODusvhd0JEE8DSTu8udJa0221/s320/theme2.png" width="213" /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2mEz2wmS87pSUvPcSFncXE-2yScXrbADlY18m5T-UXgsX3dRX_Q0g9_LIvtNtjSVd9OkiwbsQYEm9vP2zEIAa0fqYs86Ok2-b0xpvsTui9XRaDBLW7CYNSWDn4X-RvpFRDQNgVwBMcMTj/s1600/theme1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2mEz2wmS87pSUvPcSFncXE-2yScXrbADlY18m5T-UXgsX3dRX_Q0g9_LIvtNtjSVd9OkiwbsQYEm9vP2zEIAa0fqYs86Ok2-b0xpvsTui9XRaDBLW7CYNSWDn4X-RvpFRDQNgVwBMcMTj/s320/theme1.png" width="213" /></a></div><br />
<div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 1em; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: justify;"><br />
</div><br />
</div>Sanjay Patelhttp://www.blogger.com/profile/14820649584694075173noreply@blogger.com0tag:blogger.com,1999:blog-7369850069619693957.post-55623623101695575382011-05-25T22:46:00.000-07:002011-05-25T22:46:08.422-07:00error: Multiple substitutions specified in non-positional format; did you mean to add the formatted="false" attribute?<div dir="ltr" style="text-align: left;" trbidi="on"><span class="Apple-style-span" style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif;"><b>Description:<br />
This error indicates you're using a string resource with %s in it. See how to use it <a href="http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling" style="text-decoration: none;">here</a> under 'Formatting strings'. In general, instead of:</b></span><br />
<pre class="prettyprint"><b><span class="pln"><string><span class="tag"></span><span class="pln">Hello, %s! You have %d new messages.</span></string></span></b></pre><b>Should be:<br />
<pre class="prettyprint"><span class="atn"><string><span class="pln">Hello, %1$s! You have %2$d new messages.</span></string></span></pre></b></div>Sanjay Patelhttp://www.blogger.com/profile/14820649584694075173noreply@blogger.com0tag:blogger.com,1999:blog-7369850069619693957.post-13770044225749549192011-05-25T00:26:00.000-07:002011-05-25T00:26:05.373-07:00Popup SMS(Android Application)<div dir="ltr" style="text-align: left;" trbidi="on"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; color: #666666; font-family: 'Droid Sans', Arial, sans-serif; font-size: 13px; line-height: 19px;">Popup SMS brings you cool UI, fast and convenient SMS experience. Popup SMS provides a convenient popup dialog when a message is received that allows you to quickly read and reply or forward or call to messages. Quickly read and reply or forward or call to SMS messages from a convenient popup window. It also provides in-depth customization of message notifications including contact specific sound, vibrate and LED settings. Popup SMS is a tiny application, which is receiving SMS messages as a notification with popup. Have a useful experience with Message Popup. Similar to the SMS Popup app - but is faster, looks better, and is a pleasure to use.</span><br />
<div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 1em; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><br />
Full feature list:<br />
- Convenient popup window on incoming message<br />
- Quickly reply, delete, forward, call or close the message<br />
-Customize notifications including sound, vibrate pattern, LED color (if available).<br />
-Also customize notifications for individual contacts<br />
-Setup notification reminders (repeating notifications if you miss the first one)<br />
-Optional privacy mode to hide sender name and message contents</div><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 1em; padding-left: 0px; padding-right: 0px; padding-top: 0px;">Developed by :<br />
- Mitul Nakum<br />
- Sanjay Patel<br />
- Pravin Dodia</div><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 1em; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><br />
</div><div class="separator" style="clear: both; text-align: left;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZZAOSfxcnXy0Mdsj4RGez9ydqf5UQ43ef8PKkOiM9Z-FmRs6YPwCNDqsQEZq4mK62uAHc0oTIg13sDtd6bjMlcyI1cQmUy_rgrLUDrJLbtswXquHOq8rLHy2wCerB0h9VwJNcW3TGAa37/s1600/Feature+Graphic.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="156" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZZAOSfxcnXy0Mdsj4RGez9ydqf5UQ43ef8PKkOiM9Z-FmRs6YPwCNDqsQEZq4mK62uAHc0oTIg13sDtd6bjMlcyI1cQmUy_rgrLUDrJLbtswXquHOq8rLHy2wCerB0h9VwJNcW3TGAa37/s320/Feature+Graphic.png" width="320" /></a></div><br />
<div class="separator" style="clear: both; text-align: left;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEje7c-NcOvER4gbnAkQzfJzmIlJpAaBm224bQ59qF6zOpYk7MfJVE9IgWBnQ30SVfXNJtflGaV4XDN40lFHcD__CScX88UchxH80Kjh9KPf3gNLQTR891KF8U5SJy_s94FG1rckVUqyACKT/s1600/psAbout.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEje7c-NcOvER4gbnAkQzfJzmIlJpAaBm224bQ59qF6zOpYk7MfJVE9IgWBnQ30SVfXNJtflGaV4XDN40lFHcD__CScX88UchxH80Kjh9KPf3gNLQTR891KF8U5SJy_s94FG1rckVUqyACKT/s320/psAbout.png" width="213" /></a></div><br />
<div class="separator" style="clear: both; text-align: left;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3bLWf6cFGDeinbIwRZXLyENkDJBnNJwKbfASTXBDor3kct48AiLOu8s_QgJ3Ciba63Dg5PXNy501mNvpmdVZJzx4HO80frK9Hvi0KNmi0BPJYOUc47gBayQdexivrYki9L5jpsLiMzzwF/s1600/pspopup.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3bLWf6cFGDeinbIwRZXLyENkDJBnNJwKbfASTXBDor3kct48AiLOu8s_QgJ3Ciba63Dg5PXNy501mNvpmdVZJzx4HO80frK9Hvi0KNmi0BPJYOUc47gBayQdexivrYki9L5jpsLiMzzwF/s320/pspopup.png" width="213" /></a></div><br />
<div class="separator" style="clear: both; text-align: left;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimAfq5-KBOwP4BTBG5V5DQX06EoBG295Xfs3JIz_LRqpanW1Y7ijSLo6fLziHjhORHoXeQr1stdWjN3kVC3qms_h5s_lyfchiyipwKL3AnKEHfdIvpzAQYQm1NxJgz60UacxcskT0_f1k8/s1600/psPref.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimAfq5-KBOwP4BTBG5V5DQX06EoBG295Xfs3JIz_LRqpanW1Y7ijSLo6fLziHjhORHoXeQr1stdWjN3kVC3qms_h5s_lyfchiyipwKL3AnKEHfdIvpzAQYQm1NxJgz60UacxcskT0_f1k8/s320/psPref.png" width="213" /></a></div><div style="border-bottom-width: 0px; border-color: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 1em; padding-left: 0px; padding-right: 0px; padding-top: 0px;"><br />
</div></div>Sanjay Patelhttp://www.blogger.com/profile/14820649584694075173noreply@blogger.com0