Je suis en train d'apprendre et d'essayer de développer des applications dans cocos2d-x. Comment implémenter un callback à partir de WebView? J'ai utilisé le cocos2d-x v3.10.Le rappel ne peut pas être obtenu à partir du Webview dans cocos2d-x (v3.10)
test_index.html
<head>
<meta charset="utf-8">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<meta name="robots" content="none" />
<meta name="viewport" content="width=device-width,height=device-height">
</head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="js/sp.js"></script>
<ul class="slideshow">
<li>
<a href="#" onclick='sp.call("test1")'>
<img src="img/test1.jpg" width="100%"/>
</li>
</ul>
<style>
.bx-default-pager {
display: none;
}
.bx-viewport {
border: none !important;
}
</style>
</body>
sp.js
(function(){
var sp = {};
var isAndroid = navigator.userAgent.match(/Android/);
var isIOs = navigator.userAgent.match(/iPhone/) || navigator.userAgent.match(/iPod/) || navigator.userAgent.match(/iPad/);
sp.call = function(text){
if(isAndroid){
window.Cocos2dx.call(text);
} else if (isIOs) {
window.location.href = "cocos2dx:" + text;
} else {
window.location.href = text;
}
};
window.sp = sp;
})();
TEST.CPP
bool TestScene::init()
{
auto webView = cocos2d::experimental::ui::WebView::create();
webView->loadURL("http://test/test_index.html");
webview->setONJSCallback(CC_CALLBACK_1(TestScene::callbackFromJS,this));
webView->setAnchorPoint(Point(0,0));
webView->setPosition(Point(0,150));
webView->setContentSize(Size(WINSIZE.width,WINSIZE.height-150));
this->addChild(webView,1);
}
void TestScene::callbackFromJS(cocos2d::experimental::ui::WebView* webview, std::string* url)
{
log("call this method");
}
utilisation erronée de la "setOnJSCallback"?
La configuration de votre projet permet-elle d'autoriser des chargements arbitraires à partir de sites non https? – Striker
Non, Mon projet peut également accéder au https. – PluSmiles