Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何使用phonegap插件_Iphone_Cordova - Fatal编程技术网

Iphone 如何使用phonegap插件

Iphone 如何使用phonegap插件,iphone,cordova,Iphone,Cordova,我是phonegap开发方面的新手。我为iphone创建了一个插件类,其中包含一些加密方法。我想使用该.h和.m文件来加密我的数据,并从我的html页面中的类文件中获取数据。但是我不知道如何在我的javascript文件中调用该类函数作为我的页面的结果。请任何人知道如何调用任何类文件及其在iphone应用程序javascript的方法,然后帮助我。我在等待答复 参见参见参见Paul回答的链接。对于一个快速运行,有两种方法可以做到这一点,但我的通常是这样结束的东西 Javascript: Phon

我是phonegap开发方面的新手。我为iphone创建了一个插件类,其中包含一些加密方法。我想使用该.h和.m文件来加密我的数据,并从我的html页面中的类文件中获取数据。但是我不知道如何在我的javascript文件中调用该类函数作为我的页面的结果。请任何人知道如何调用任何类文件及其在iphone应用程序javascript的方法,然后帮助我。我在等待答复

参见

参见

参见Paul回答的链接。对于一个快速运行,有两种方法可以做到这一点,但我的通常是这样结束的东西

Javascript:

PhoneGap.exec("NameOfObjectiveCFile.nameofMethod","parameter1", "parameter2");
目标C:

-(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];

    }
回到Javascript:

function nameofJavascriptFinishedMethod(parameterFromObjectiveC)
{
   //Do stuff with information from objective C
}
还请记住,您需要在Phonegap.plist中注册插件 希望这有帮助,祝你好运

更新:如果您希望html向插件发送信息,我会使用html表单或按钮或触发一个操作,调用javascript函数(上面的第一个函数)并传递从字段中收集的变量。有关表单基础知识,请参见此

更新2
1) 在xcode中创建新的phonegap项目并构建以获取www文件夹
2) 将现有的加密目标C文件添加到project中
3) 创建新的objective C类,称之为EncryptPlugin(下一步请参见步骤5)
4) 编辑PhoneGap.plist文件
a) 在插件下添加新条目
b) 将其命名为EncryptPlugin String EncryptPlugin
5) EncryptPlugin的头文件应该如下所示

#import <Foundation/Foundation.h>
#import <UIKit/UIkit.h>

#ifdef PHONEGAP_FRAMEWORK
#import <PhoneGap/PGPlugin.h>
#else
#import "PGPlugin.h"
#endif

@interface EncryptPlugin : PGPlugin {



}
-(void) useMyEncryptionFiles:(NSMutableArray*)paramArray withDict:(NSMutableDictionary*)options;
@end
#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
7) 在您的html javascript中,使用如下内容调用函数 p1.html


希望这会有所帮助,您应该能够通过这些说明来理解它。它们可能并不完美,但我没有时间将它们全部放在一起,并使用您的代码进行编译。祝你好运。

查看保罗回答的链接。对于一个快速运行,有两种方法可以做到这一点,但我的通常是这样结束的东西

Javascript:

PhoneGap.exec("NameOfObjectiveCFile.nameofMethod","parameter1", "parameter2");
目标C:

-(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];

    }
回到Javascript:

function nameofJavascriptFinishedMethod(parameterFromObjectiveC)
{
   //Do stuff with information from objective C
}
还请记住,您需要在Phonegap.plist中注册插件 希望这有帮助,祝你好运

更新:如果您希望html向插件发送信息,我会使用html表单或按钮或触发一个操作,调用javascript函数(上面的第一个函数)并传递从字段中收集的变量。有关表单基础知识,请参见此

更新2
1) 在xcode中创建新的phonegap项目并构建以获取www文件夹
2) 将现有的加密目标C文件添加到project中
3) 创建新的objective C类,称之为EncryptPlugin(下一步请参见步骤5)
4) 编辑PhoneGap.plist文件
a) 在插件下添加新条目
b) 将其命名为EncryptPlugin String EncryptPlugin
5) EncryptPlugin的头文件应该如下所示

#import <Foundation/Foundation.h>
#import <UIKit/UIkit.h>

#ifdef PHONEGAP_FRAMEWORK
#import <PhoneGap/PGPlugin.h>
#else
#import "PGPlugin.h"
#endif

@interface EncryptPlugin : PGPlugin {



}
-(void) useMyEncryptionFiles:(NSMutableArray*)paramArray withDict:(NSMutableDictionary*)options;
@end
#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
7) 在您的html javascript中,使用如下内容调用函数 p1.html


希望这会有所帮助,您应该能够通过这些说明来理解它。它们可能并不完美,但我没有时间将它们全部放在一起,并使用您的代码进行编译。祝你好运。

从JavaScript调用Obj C函数。从JavaScript调用Obj C函数。亲爱的hatunike,请您指导我如何获取html文本输入以及如何将输入发送到插件类。以及安装插件类所需的代码。如果您有任何想法,请指导我您想要设置一个html表单。提交后,使用上述过程将变量发送到您想要的插件。亲爱的hatunike,请您指导我如何获取html文本输入以及如何将输入发送到插件类。以及安装插件类所需的代码。如果您有任何想法,请指导我您想要设置一个html表单。提交后,使用上述过程将变量发送到您想要的插件。我将尝试编辑答案,以便更有帮助。