Ⅰ cordova ios 環境搭建css html js之間是怎麼跟oc輪著調用
1.在你的html5中config.js定義你的Plugin的名稱和方法。名為MyPlugin,有兩個插件:一個為自動更新(Update),一個為密碼鎖定(PassLock)
var MyPlugin = {
UpDate: function (success, fail, url) {
return PhoneGap.exec(function (args) {
success(args);
}, function (args) {
fail(args);
}, 'UpDate', 'Update', [url]);
},
PassLock: function (success, fail, url){
return PhoneGap.exec(function (args) {
success(args);
}, function (args) {
fail(args);
}, 'PassLock', 'PassLock', [url]);
}
};
2.在xml文件夾下的plugin里注冊你的Plugin.
<plugin name="UpDate" value="com.gapsh.plugin.UpdatePlugin"/>
<plugin name="PassLock" value="com.gapsh.plugin.PassLockPlugin"/>
3.自定義你的Plugin類和處理方法.(這里只貼出了自動更新插件的代碼,很簡單,只是作了一個跳轉)
public class UpdatePlugin extends Plugin {
@Override
public PluginResult execute(String arg0, JSONArray arg1, String arg2) {
/*
* 跳轉到UpdateActivity
*/
Intent intent = new Intent(ctx.getContext(),UpdateActivity.class);
ctx.startActivity(intent);
String result = "跳轉至UpdateActivity";
PluginResult pluginResult = new PluginResult(Status.OK, result);
return pluginResult;
}
}
4.在你的JS中調用你的插件。
//自動更新
upDate: function () {
//調用android原生的方法檢查並更新
MyPlugin.UpDate(function(){},function(){},'這里是一個參數,我這里不涉及參數的使用,所以隨便寫');
},
passLock: function(){
//調用android原生的方法進行密碼鎖定有關操作
MyPlugin.PassLock(function(){},function(){},'這里是一個參數,我這里不涉及參數的使用,所隨便寫');
},
5.測試,當你點擊你的某個按鈕或者鏈接執行你的update:function這個JS,然後在JS里調用了MyPlugin下的Update插件,這個插件在config.js里被定義,在plugin.xml中被注冊,插件具體執行的地方時UpdatePlugin里的execute()方法。執行完這個方法後,你就已經調用了Android的原生代碼咯,當然我這里是設置成了跳轉到另外一個Activity.
Ⅱ 在oc渲染器中怎麼弄環境吸收效果
你沒有在渲染設置里添加環境吸收效果。
1.在渲染設置里點擊效果。添加環境吸收。就可以調整環境吸收參數了。
2.AO單獨渲染,不但要啟用多通道渲染的,環境吸收。還要在渲染設置的,保存設置里,設置多通道圖像的,保存位置,和關閉多層文件。
這樣AO就可以單獨渲染出來了。
Ⅲ oc html5格式的數據怎麼解析
var data1=new Date("1990/01/01").getTime(); 轉化成毫秒 對比就行了.
Ⅳ OC代碼如何與HTML內容交互通知
javascript
="url="+$("#url").val();$.ajax({type:"POST",url:"targetAction!targetMethod.action",data:param,dataType:"json",success:function(json){alert(json);},error:function(){alert("連接超時");}});
java
=ServletActionContext.getResponse();response.resetBuffer();response.setCharacterEncoding("utf-8");response.getWriter().print(JSONArray.fromObject(data));
js端需要有個jquery,java端需要有個json-lib,這兩個你可以到網上下載
Ⅳ IOS打開一個本地html,怎麼給他帶上一個參數
本地文件不可以url直接加參數,可以在uiwebview 載入好後 用js和oc 交互,傳遞參數。
參考:
NSURL*urlNosmoke=[NSURLURLWithString:[NSStringstringWithFormat:@"nosmokeProgram.html"]];
NSString*strFilePath=[self.viewController.:[urlNosmokepath]];
NSURL*urlNonSmoking=[NSURLURLWithString:@"?nonSmokingId=2013"relativeToURL:[NSURLURLWithString:strFilePath]];
NSURLRequest*req=[[NSURLRequestalloc]initWithURL:urlNonSmoking
cachePolicy:
timeoutInterval:20.0f];
[self.viewController.webViewEngineloadRequest:req];
Ⅵ oc如何引用html5寫的登錄頁面
1.利用webView控制項載入本地html5或者網路上html52.設置控制器為webView的代理,遵守協議3.實現代理方法webViewDidFinishLoad:4.在代理方法中進行操作HTML5中的標簽(CRUD-->增刪改查)
1.用類選擇器或者id選擇器或者標簽選擇器等選擇要進行操作的標簽
2.把選擇好的標簽轉換成字元串
3.webView調用方法
1.載入本地HTML5
2.載入網路上網頁HTML5
3.在oc中刪除HTML5中的某個標簽,比如按鈕
4.在oc中更改HTML5內容
Ⅶ HTML與oc的交互,相互回調的問題
//
// ViewController.m
// OC_And_JS
//
// Created by 張傑 on 15/7/9.
// Copyright © 2015年 張傑. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_mWebView.delegate = self;
//打開URL
NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
[self.mWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath: path]]];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
NSString *urlstr = request.URL.absoluteString;
NSRange range = [urlstr rangeOfString:@"ios://jwzhangjie"];
if (range.length!=0) {
_js_call_oc_show.text = [NSString stringWithFormat:@"請訪問地址:%@", urlstr];
}
return YES;
}
-(void)webView:(nonnull UIWebView *)webView didFailLoadWithError:(nullable NSError *)error{
NSLog(@"載入失敗");
}
-(void)webViewDidStartLoad:(nonnull UIWebView *)webView{
NSLog(@"開始載入");
}
-(void)webViewDidFinishLoad:(nonnull UIWebView *)webView{
NSLog(@"開始結束");
// 對於調用js的時候最好這個方法裡面或者之後
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)ocCallJsNoParams:(id)sender {
NSString *js = [NSString stringWithFormat:@"ocCallJsNoParamsFunction();"];
[self.mWebView :js];
}
- (IBAction)ocCallJsHasParams:(id)sender {
NSString *js = [NSString stringWithFormat:@"ocCallJsHasParamsFunction('%@','%@');",@"jwzhangjie",@"http://jwzhangjie.cn"];
[self.mWebView :js];
}
@end
Ⅷ ios oc掉js並修改html界面 需要非同步嗎
使用示例: 下面的示例代碼將調用上面NativeOcClass的方法,在js層只需要這樣調用: var ret = jsb.reflection.callStaticMethod("NativeOcClass", "callNativeUIWithTitle:andContent:", "cocos2d-js", "Yes! you call a Native UI from Reflection"); 這里是這個方法在OC的實現,可以看到是彈出一個native的對話框。並把title和content設置成傳入的參數,並返回一個boolean類型的返回值。 +(BOOL)callNativeUIWithTitle:(NSString *) title andContent:(NSString *)content{ UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:content delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; [alertView show]; return true; } 此時,就可以在ret中接受到從OC傳回的返回值(true)了。 注意: 在OC的實現中,如果方法的參數需要使用float、int、bool的,請使用如下類型進行轉換: float,int 請使用NSNumber類型 bool請使用BOOL類型。 例如下面代碼,傳入2個浮點數,然後計算他們的合並返回,使用NSNumber而不是int、float去作為參數類型。 +(float) addTwoNumber:(NSNumber *)num1 and:(NSNumber *)num2{ float result = [num1 floatValue]+[num2 floatValue]; return result; }
Ⅸ 登錄網站顯示octype+html登錄不上怎麼回事
摘要 這類型的網站用360瀏覽器是登錄不了的
Ⅹ iOS開發 怎麼實現js調取oc中的方法
我們要做的有如下幾件事情:
首先:通過webview載入一個本地html文件
[self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"]isDirectory:NO]]];
其次:我們要在我們的OC代碼裡面注冊JS方法
- (void)h5callApp
{
//獲取該UIWebview的javascript執行環境。
JSContext *context = [self.myWebView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
context.exceptionHandler = ^(JSContext *con, JSValue *exception) {
NSLog(@"%@", exception);
con.exception = exception;
};
context[@"h5CallApp"] = ^() {
NSLog(@"+++++++Begin Log+++++++");
NSArray *args = [JSContext currentArguments];
for (JSValue *jsVal in args) {
NSLog(@"%@", jsVal);
}
JSValue *this = [JSContext currentThis];
NSLog(@"this: %@",this);
NSLog(@"-------End Log-------");
};
}
要保證本地的html裡面有h5CallApp這個方法哦。
這就是剛剛上述博客裡面提到的方法,是不是看上次很簡單的樣子。
But
我運用到我們項目裡面的時候,死活不能調用該方法,why?我厚著臉皮問了我們的帥哥安卓開發,得知他們裡面有這一樣一行代碼
webView.addJavascriptInterface(new JSInvoke(), "test");
看上去第一眼的感覺是不是累似注冊了一個東西,可是我找了好多博客我沒有找到我們IOS類似的啊,著急啊著急。
意外的意外,偉大的github上面就是資源多,我在上面找到一個EasyJSWebViewSample這樣一個開源項目,裡面有一句
MyJSInterface* interface = [MyJSInterface new];
[self.myWebView addJavascriptInterfaces:interface WithName:@"MyJSTest"];
是不是感覺和安卓裡面的那個注冊類似的,沒錯,太開心了。
最後的最後,你以為結束了,NO!
該Demo裡面的html有空的小朋友可以看一下。
由於項目需求我們是3個參數,在該demo裡面執行拿到第一個參數,該demo就運行出錯,提示我們數組越界了,在這里真的浪費了好多時間,後來發現他們的demo裡面調用兩個參數的方法在JS裡面聲明的方法與OC裡面真正的實現方法有點差入,比如OC裡面定義的方法
- (void) h5CallApp: (NSString*) param And2: (NSString*) param2 And3: (NSString*) param3
在html裡面只能寫成
MyJSTest.h5CallAppAnd2And3("param1","param2","param3")。
是不是覺得不可思義,最後我整體看了一下代碼,裡面好像有這一段在注入JS的時候有用到的
inject: function (obj, methods){\\
window[obj] = {};\\
var jsObj = window[obj];\\
\\
for (var i = 0, l = methods.length; i < l; i++){\\
(function (){\\
var method = methods[i];\\
var jsMethod = method.replace(new RegExp(\\":\\", \\"g\\"), \\"\\");\\
jsObj[jsMethod] = function (){\\
return EasyJS.call(obj, method, Array.prototype.slice.call(arguments));\\
};\\
})();\\
}\\
}
這個好像是替換方法的,原諒我的無知啊,我也是沒看懂,僅僅是感覺與猜測,勿噴我,我真的怕被噴。
最後的最後,JS的那邊的開發肯定是不會為了將IOS與安卓開發做區分寫代碼的,所以我只能在注入JS完成後加了這么一句
[webView :@"test.h5CallApp=test.h5CallAppAnd2And3;"]
這句話的作用是替換JS裡面的方法的。