xcode Phonegap:window.device 在 iOS 上未定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18475411/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:44:21  来源:igfitidea点击:

Phonegap: window.device is undefined on iOS

iosxcodecordovaundefineddevice

提问by stolli

I realize this has been asked before, but it has not been adequately answered. I am running phonegap on ios. My deviceready event is firing, but I cannot ever find window.device or device, as in "device.uuid" or "device.model."

我意识到以前有人问过这个问题,但没有得到充分的回答。我在 ios 上运行 phonegap。我的 deviceready 事件正在触发,但我找不到 window.device 或设备,如“device.uuid”或“device.model”。

It just isn't there. I reference it in the device ready event, yet no luck.

它只是不存在。我在设备就绪事件中引用了它,但没有运气。

In the safari debugger, it just says 'undefined' is not an object (evaluating 'window.device.uuid')

在 safari 调试器中,它只是说“未定义”不是一个对象(评估“window.device.uuid”)

any help?

有什么帮助吗?

回答by avoision

What version of PhoneGap are you using? If it's 3.0, you'll need to install each device-level API as a plugin.

您使用的是哪个版本的 PhoneGap?如果是 3.0,则需要将每个设备级 API 作为插件安装。

In the past, I think many of these were readily available out of the box. But with 3.0, I think you need to go and install a plugin for every API you want access to. So there's a separate plugin you need to install to access Accelerometer, Camera, etc... and a separate one for the device object.

在过去,我认为其中许多都是现成的。但是对于 3.0,我认为您需要为您想要访问的每个 API 安装一个插件。因此,您需要安装一个单独的插件来访问加速度计、相机等……以及一个单独的用于设备对象的插件。

I'm still getting adjusted to this (very much a command-line noob), but if you're working with 3.0 this might be your issue.

我仍在对此进行调整(非常像命令行菜鸟),但是如果您使用的是 3.0,这可能是您的问题。

For more info, see Accessing the Feature, here: http://docs.phonegap.com/en/edge/cordova_device_device.md.html#Device

有关详细信息,请参阅访问该功能,此处:http: //docs.phonegap.com/en/edge/cordova_device_device.md.html#Device

回答by Anup

I have used it and it works. Can you post your code?

我已经使用它并且它有效。你能贴出你的代码吗?

Also refer to the code: http://docs.phonegap.com/en/edge/cordova_device_device.md.html#device.name

另请参阅代码:http: //docs.phonegap.com/en/edge/cordova_device_device.md.html#device.name