在Sencha touch中运行Hello World程序(基本)
问题描述:
我有2个问题,关于Sencha touch
和phone gap
;在Sencha touch中运行Hello World程序(基本)
我正在阅读Ajith kumar的SenchaTouch CookBook。我遵循第1章给出的示例程序。所以根据我做了以下。
这是我index.html
<!DOCTYPE HTML>
<html>
<head>
<title>Yapps! - Your daily applications!</title>
<link rel="stylesheet" href="sencha-
touch/resources/css/sencha-touch.css" type="text/css">
<link rel="stylesheet" href="sencha-
touch/resources/css/yapps-all.css" type="text/css">
<script type="text/javascript" charset="utf-8"
src="phonegap.1.0.0.js"></script>
<script type="text/javascript" charset="utf-8" src="sencha-
touch/sencha-touch.js"></script>
<script type="text/javascript" charset="utf-8"
src="ch01/ch01_03.js"></script>
<script type="text/javascript" charset="utf-8" src="sencha-
touch/yapps-all.js"></script>
</head>
<body></body>
</html>
的ch01_03.js
文件。告诉在WWW文件夹中添加这些.JS文件,但是我无法在该文件夹内添加任何文件,因此我将其添加到该文件夹中。
Ext.setup({
onReady: function() {
var supportedFeatures = "Ext.supports.AudioTag : " +
(Ext.supports.AudioTag ? "On" : "Off");
supportedFeatures += "\nExt.supports.CSS3BorderRadius : " +
(Ext.supports.CSS3BorderRadius ? "On" : "Off");
supportedFeatures += "\nExt.supports.CSS3DTransform : " +
(Ext.supports.CSS3DTransform ? "On" : "Off");
supportedFeatures += "\nExt.supports.CSS3LinearGradient : " +
(Ext.supports.CSS3LinearGradient ? "On" : "Off");
supportedFeatures += "\nExt.supports.Canvas : " +
(Ext.supports.Canvas ? "On" : "Off");
supportedFeatures += "\nExt.supports.DeviceMotion : " +
(Ext.supports.DeviceMotion ? "On" : "Off");
supportedFeatures += "\nExt.supports.Float : " +
(Ext.supports.Float ? "On" : "Off");
supportedFeatures += "\nExt.supports.GeoLocation : " +
(Ext.supports.GeoLocation ? "On" : "Off");
supportedFeatures += "\nExt.supports.History : " +
(Ext.supports.History ? "On" : "Off");
supportedFeatures += "\nExt.supports.OrientationChange : " +
(Ext.supports.OrientationChange ? "On" : "Off");
supportedFeatures += "\nExt.supports.RightMargin : " +
(Ext.supports.RightMargin ? "On" : "Off");
supportedFeatures += "\nExt.supports.SVG : " +
(Ext.supports.SVG ? "On" : "Off");
supportedFeatures += "\nExt.supports.Touch : " +
(Ext.supports.Touch ? "On" : "Off");
supportedFeatures += "\nExt.supports.Transitions : " +
(Ext.supports.Transitions ? "On" : "Off");
supportedFeatures += "\nExt.supports.TransparentColor : " +
(Ext.supports.TransparentColor ? "On" : "Off");
supportedFeatures += "\nExt.supports.VML : " +
(Ext.supports.VML ? "On" : "Off");
Ext.Msg.alert("INFO", supportedFeatures);
}
});
1.)问题是,我只看到一个空白的屏幕,当我在我的iPhone和刺激器上运行它。这是怎么回事,我该怎么做才能让警报显示在视图上?
2.)我需要检测设备是否运行应用程序。本书介绍了如何检测iPad,Android应用程序和Blackberry。但不是iPhone。我如何检测iPhone?
Ext.setup({
onReady: function() {
if (Ext.is.Android)
Ext.Msg.alert("INFO", "Welcome Android user!");
if (Ext.is.Blackberry)
Ext.Msg.alert("INFO", "Welcome Blackberry user!");
if (Ext.is.iPad)
Ext.Msg.alert("INFO", "Welcome iPad user!");
} });
答
由于这个问题是sencha-touch-2
下标记,我假设你正在使用煎茶触摸2.
Ext.is
已经废弃了煎茶触摸版本2.0
相反,你可以使用Ext.env.OS
包检测正在设备上运行的操作系统。
此外,您还可以使用为物业检测喜欢iPad,iPhone,安卓等一p'cular设备..
-
Ext.os.is.Android
:Android平台 -
Ext.os.is.iPhone
:iPhone -
Ext.os.is.iPad
:iPad的等等。
编辑:
是的,您可以检测到“绿色”设备。检查下面的代码...
var navigation = Ext.global.navigator,
userAgent = navigation.userAgent,
osEnv, osName, deviceType;
Ext.os = osEnv = new this(userAgent, navigation.platform);
osName = osEnv.name;
var search = window.location.search.match(/deviceType=(Tablet|Phone)/),
nativeDeviceType = window.deviceType;
if (search && search[1]) {
deviceType = search[1];
}
else if (nativeDeviceType === 'iPhone') {
deviceType = 'Phone';
}
else if (nativeDeviceType === 'iPad') {
deviceType = 'Tablet';
}
1.很好的例子)谢谢您的reply.But仍然在Xcode不建议'iPhone'(它暗示的Android,iPad和黑莓但没有iPhone)。 2.)我认为在index.html中,我指的是一个不在正确文件路径中的文件。我没有在'WWW'文件夹中添加'ch01/ch01_03.js',我已经将它添加到'WWW'文件夹之外,因为我不允许在'WWW'文件夹中添加文件。那么我怎样才能访问'cho1_03.js'文件? – user1315906 2012-04-28 08:51:13
您需要将该文件包含在'www'文件夹中,否则将无法访问该文件。为什么你不能在'www'文件夹中添加它? – 2012-04-28 09:45:10
此外,检查编辑的代码,以检测像iPhone,iPad等设备... – 2012-04-28 09:52:26