Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>See the link that Paul answered. For a quick run down, there are a couple ways to do this, but mine usually end up something like this.</p> <p>Javascript:</p> <pre><code>PhoneGap.exec("NameOfObjectiveCFile.nameofMethod","parameter1", "parameter2"); </code></pre> <p>Objective C:</p> <pre><code>-(void)nameOfMethod:(NSMutableArray*)paramArray withDict: (NSMutableDictionary*) options { //Do your stuff //Access your params you sent in javascript by doing the following NSString *parameter1 = [paramArray objectAtIndex:0]; //Send stuff back to Javascript using a callback function NSString *jsCallBack = [NSString stringWithFormat:@"nameofJavascriptFinishedMethod(%@)",parameterToSendBack]; [self.webview stringByEvaluatingJavaScriptFromString:jsCallBack]; } </code></pre> <p>Back to Javascript: </p> <pre><code>function nameofJavascriptFinishedMethod(parameterFromObjectiveC) { //Do stuff with information from objective C } </code></pre> <p>Also remember you need to register your plugin in your Phonegap.plist Hope this helps, good luck.</p> <p><strong>Update</strong>: If you want your html to send information to your plugin, i'd use an html form or button or trigger an action that will call your javascript function (The first one above) and pass your variables gathered from your fields. See this <a href="http://www.w3schools.com/html/html_forms.asp" rel="nofollow">link</a> for form basics. </p> <p><strong>Update 2</strong><br> 1)Create new phonegap project in xcode and build to get www folder<br> 2)Add your existing Encryption objective C files to project<br> 3)Create new objective C class, call it EncryptPlugin (See step 5 for next)<br> 4)Edit PhoneGap.plist file<br> a)add a new entry under Plugins<br> b)name it EncryptPlugin String EncryptPlugin<br> 5)Header file for EncryptPlugin should look like this </p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #import &lt;UIKit/UIkit.h&gt; #ifdef PHONEGAP_FRAMEWORK #import &lt;PhoneGap/PGPlugin.h&gt; #else #import "PGPlugin.h" #endif @interface EncryptPlugin : PGPlugin { } -(void) useMyEncryptionFiles:(NSMutableArray*)paramArray withDict:(NSMutableDictionary*)options; @end </code></pre> <p>6)Implementation file should look like this </p> <pre><code>#import "EncryptPlugin.h" #import "EncryptPacket.h" @implementation EncryptPlugin //phonegap magic -- basically ignore -(PGPlugin*) initWithWebView:(UIWebView*)theWebView { self = (PdfCreator*)[super initWithWebView:theWebView]; return self; } //The method that your javascript is going to call -(void) useMyEncryptionFiles:(NSMutableArray*)paramArray withDict:(NSMutableDictionary*)options { //This gives you your string NSString *stringFromJavascript = [paramArray objectAtIndex:0]; EncryptPacket *ep = [[EncryptPacket alloc] init]; NSString *encryptedString = [ep encryptRequest:stringFromJavascript]; NSLog(@"encryptedString = %@",encryptedString); } @end </code></pre> <p>7)In your html javascript call the function using something like this p1.html</p> <pre><code>&lt;head&gt;&lt;script type="text/javascript" src="encryptdata.js"&gt;&lt;/script&gt;&lt;/head&gt; &lt;body&gt; &lt;input type="password" name="confirmPassword" id="confirmPassword" value="" /&gt; &lt;input type="button" value="FetchR" onclick="fetchRelation()"/&gt; &lt;/body&gt; encryptdata.js function fetchRelation() { var getvalue=document.getElementById('confirmPassword').value; //what is next step....... to send the data to the plugin class PhoneGap.exec("EncryptPlugin.useMyEncrptionFiles",getValue); } </code></pre> <p>This should get you started. If you want to send stuff back to your html javascript then use the function I specified above:</p> <pre><code>NSString *jsCallBack = [NSStringstringWithFormat:@"nameofJavascriptFinishedMethod(%@)",parameterToSendBack]; [self.webview stringByEvaluatingJavaScriptFromString:jsCallBack]; </code></pre> <p>Hopefully this helps, you should be able to figure it out with these instructions. They probably aren't perfect, but I didn't have time to put it all together and compile it using your code. Good luck.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload