js交互

来源:互联网 发布:iphone6网络连接不上 编辑:程序博客网 时间:2024/06/06 01:31


oc调用js

//[myWebView stringByEvaluatingJavaScriptFromString:@"submitForm();"];




//   js调用oc

//网页加载完成调用此方法

//    //首先创建JSContext对象(此处通过当前webView的键获取到jscontext

//    context1 =[webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];

//    //第二种情况,js是通过对象调用的,我们假设js里面有一个对象 testobject 在调用方法

//    //首先创建我们新建类的对象,将他赋值给js的对象

//    Js_Lei *testJO=[Js_Lei new];

//    context1[@"TrcbankApp"]=testJO;

//    testJO.delegate = self;




Js_Lei类.h

import <Foundation/Foundation.h>

#import <JavaScriptCore/JavaScriptCore.h>


//首先创建一个实现了JSExport协议的协议

@protocol TestJSObjectProtocol <JSExport>

//此处我们测试几种参数的情况

-(void)showLoading;

-(void)hideLoading;


@end

@protocol JSObjectData <NSObject>


//此为代理方法名

- (void)gotoNextVC1;

- (void)gotoNextVC2;


@end

@interface Js_Lei :NSObject<TestJSObjectProtocol>

@property (nonatomic ,assign) id<JSObjectData>delegate;


@end



Js_Lei类.m

#import "Js_Lei.h"


@implementation Js_Lei


-(void)showLoading

{

//    NSLog(@"this is ios TestNOParameter");

    [self.delegategotoNextVC1];


}

-(void)hideLoading

{

//    NSLog(@"this is ios TestOneParameter");

    [self.delegategotoNextVC2];


}



@end


0 0
原创粉丝点击