Tôi đang gặp sự cố thực sự với PhoneGap trong iPhone với các sự kiện. Các ứng dụng đang chạy khá trơn tru trong thiết bị Android của tôi, nhưng trên iPhone của tôi nó không phải bất cứ điều gì. Ví dụ: một mã đơn giản như sau:Sự kiện Phonegap không hoạt động trong iphone
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0;" />
<meta charset="utf-8">
<title>WayAcross Mobile Application</title>
<link rel="stylesheet" href="css/jquery.css" />
<link rel="stylesheet" href="css/screen.css" />
<link rel="stylesheet" href="css/login.css" />
<script type="text/javascript" charset="utf-8" src="jquery/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="jquery/jquery.mobile.js"></script>
<script type="text/javascript" charset="UTF-8" src="javascript/mainJavascript.js"></script>
<script type="text/javascript" charset="utf-8">
// Call onDeviceReady when PhoneGap is loaded.
//
// At this point, the document has loaded but phonegap.js has not.
// When PhoneGap is loaded and talking with the native device,
// it will call the event `deviceready`.
//
function onLoad(){
document.addEventListener("deviceready", onDeviceReady, false);
}
// PhoneGap is loaded and it is now safe to make calls PhoneGap methods
//
function onDeviceReady() {
// Now safe to use the PhoneGap API
alert('ready');
}
</script>
<script type="text/javascript" charset="utf-8" src="javascript/phonegap.js"></script>
</head>
<body onload="onLoad()">
(đây là ví dụ mã không hoạt động với iPhone và hoạt động với Android).
Tôi nghĩ rằng đó là vấn đề với các sự kiện, nhưng tôi không chắc chắn. Ngay cả các ví dụ mã trong tài liệu PhoneGap cũng không hoạt động. môi trường của tôi là:
- Mac OSX 10.7.1
- Xcode 4.1
- PhoneGap 1.1
- jQuery Mobile 1.0RC Điều duy nhất mà nó cho thấy tôi là thế này: http://cl.ly/0h462Y2D2F0J0B1B0q1M
Cảm ơn trước.
Kính trọng,
Elkas
Bằng cách này, tôi đã cài đặt OSX Lion 10.7.2 và Xcode 4.2 bây giờ. Ngay cả trong IOS5 nó không hoạt động. Điều này khiến tôi điên mất!!! Ngay cả với mã đơn giản này không hoạt động.
<!DOCTYPE html>
<html>
<head>
<title>PhoneGap Device Ready Example</title>
<script type="text/javascript" charset="utf-8">
// Call onDeviceReady when PhoneGap is loaded.
//
// At this point, the document has loaded but phonegap.js has not.
// When PhoneGap is loaded and talking with the native device,
// it will call the event `deviceready`.
//
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is loaded and it is now safe to make calls PhoneGap methods
//
function onDeviceReady() {
alert('Hello World');
}
</script>
<script type="text/javascript" charset="utf-8" src="javascript/phonegap.js"</script>
</head>
<body>
</body>
</html>
Mọi thứ đều ổn, hãy thử ghi lại nội dung bằng cách sử dụng alert() để tìm hiểu vị trí không thành công. – sciritai
Cũng thử điều đó. nếu tôi đặt onload = "onDeviceReady()" trong thẻ body hoặc một chức năng khác, nó sẽ hiển thị cảnh báo nhưng các sự kiện "phonegap" vẫn không hoạt động. = ( – Elkas
jQuery mobile sẽ được thêm * sau * tập lệnh tùy chỉnh. – Walf