- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
询问关于 cordova device.uuid javascript 的问题?
我在哪里可以获得这个用于 cordova.js
的目录
cordova/channel
cordova/platform
我将这段代码用于主页
<!DOCTYPE html>
<html>
<head>
<title>Device Properties Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
var element = document.getElementById('deviceProperties');
element.innerHTML = 'Device Name: ' + device.name + '<br />' +
'Device Cordova: ' + device.cordova + '<br />' +
'Device Platform: ' + device.platform + '<br />' +
'Device UUID: ' + device.uuid + '<br />' +
'Device Model: ' + device.model + '<br />' +
'Device Version: ' + device.version + '<br />';
}
</script>
</head>
<body>
<p id="deviceProperties">Loading device properties...</p>
</body>
</html>
这是 cordova.js
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
// Workaround for Windows 10 in hosted environment case
// http://www.w3.org/html/wg/drafts/html/master/browsers.html#named-access-on-the-window-object
if (window.cordova && !(window.cordova instanceof HTMLElement)) {
throw new Error("cordova already defined");
}
var channel = require('cordova/channel');
var platform = require('cordova/platform');
/**
* Intercept calls to addEventListener + removeEventListener and handle deviceready,
* resume, and pause events.
*/
var m_document_addEventListener = document.addEventListener;
var m_document_removeEventListener = document.removeEventListener;
var m_window_addEventListener = window.addEventListener;
var m_window_removeEventListener = window.removeEventListener;
/**
* Houses custom event handlers to intercept on document + window event listeners.
*/
var documentEventHandlers = {},
windowEventHandlers = {};
document.addEventListener = function(evt, handler, capture) {
var e = evt.toLowerCase();
if (typeof documentEventHandlers[e] != 'undefined') {
documentEventHandlers[e].subscribe(handler);
} else {
m_document_addEventListener.call(document, evt, handler, capture);
}
};
window.addEventListener = function(evt, handler, capture) {
var e = evt.toLowerCase();
if (typeof windowEventHandlers[e] != 'undefined') {
windowEventHandlers[e].subscribe(handler);
} else {
m_window_addEventListener.call(window, evt, handler, capture);
}
};
document.removeEventListener = function(evt, handler, capture) {
var e = evt.toLowerCase();
// If unsubscribing from an event that is handled by a plugin
if (typeof documentEventHandlers[e] != "undefined") {
documentEventHandlers[e].unsubscribe(handler);
} else {
m_document_removeEventListener.call(document, evt, handler, capture);
}
};
window.removeEventListener = function(evt, handler, capture) {
var e = evt.toLowerCase();
// If unsubscribing from an event that is handled by a plugin
if (typeof windowEventHandlers[e] != "undefined") {
windowEventHandlers[e].unsubscribe(handler);
} else {
m_window_removeEventListener.call(window, evt, handler, capture);
}
};
function createEvent(type, data) {
var event = document.createEvent('Events');
event.initEvent(type, false, false);
if (data) {
for (var i in data) {
if (data.hasOwnProperty(i)) {
event[i] = data[i];
}
}
}
return event;
}
var cordova = {
define:define,
require:require,
version:PLATFORM_VERSION_BUILD_LABEL,
platformVersion:PLATFORM_VERSION_BUILD_LABEL,
platformId:platform.id,
/**
* Methods to add/remove your own addEventListener hijacking on document + window.
*/
addWindowEventHandler:function(event) {
return (windowEventHandlers[event] = channel.create(event));
},
addStickyDocumentEventHandler:function(event) {
return (documentEventHandlers[event] = channel.createSticky(event));
},
addDocumentEventHandler:function(event) {
return (documentEventHandlers[event] = channel.create(event));
},
removeWindowEventHandler:function(event) {
delete windowEventHandlers[event];
},
removeDocumentEventHandler:function(event) {
delete documentEventHandlers[event];
},
/**
* Retrieve original event handlers that were replaced by Cordova
*
* @return object
*/
getOriginalHandlers: function() {
return {'document': {'addEventListener': m_document_addEventListener, 'removeEventListener': m_document_removeEventListener},
'window': {'addEventListener': m_window_addEventListener, 'removeEventListener': m_window_removeEventListener}};
},
/**
* Method to fire event from native code
* bNoDetach is required for events which cause an exception which needs to be caught in native code
*/
fireDocumentEvent: function(type, data, bNoDetach) {
var evt = createEvent(type, data);
if (typeof documentEventHandlers[type] != 'undefined') {
if( bNoDetach ) {
documentEventHandlers[type].fire(evt);
}
else {
setTimeout(function() {
// Fire deviceready on listeners that were registered before cordova.js was loaded.
if (type == 'deviceready') {
document.dispatchEvent(evt);
}
documentEventHandlers[type].fire(evt);
}, 0);
}
} else {
document.dispatchEvent(evt);
}
},
fireWindowEvent: function(type, data) {
var evt = createEvent(type,data);
if (typeof windowEventHandlers[type] != 'undefined') {
setTimeout(function() {
windowEventHandlers[type].fire(evt);
}, 0);
} else {
window.dispatchEvent(evt);
}
},
/**
* Plugin callback mechanism.
*/
// Randomize the starting callbackId to avoid collisions after refreshing or navigating.
// This way, it's very unlikely that any new callback would get the same callbackId as an old callback.
callbackId: Math.floor(Math.random() * 2000000000),
callbacks: {},
callbackStatus: {
NO_RESULT: 0,
OK: 1,
CLASS_NOT_FOUND_EXCEPTION: 2,
ILLEGAL_ACCESS_EXCEPTION: 3,
INSTANTIATION_EXCEPTION: 4,
MALFORMED_URL_EXCEPTION: 5,
IO_EXCEPTION: 6,
INVALID_ACTION: 7,
JSON_EXCEPTION: 8,
ERROR: 9
},
/**
* Called by native code when returning successful result from an action.
*/
callbackSuccess: function(callbackId, args) {
cordova.callbackFromNative(callbackId, true, args.status, [args.message], args.keepCallback);
},
/**
* Called by native code when returning error result from an action.
*/
callbackError: function(callbackId, args) {
// TODO: Deprecate callbackSuccess and callbackError in favour of callbackFromNative.
// Derive success from status.
cordova.callbackFromNative(callbackId, false, args.status, [args.message], args.keepCallback);
},
/**
* Called by native code when returning the result from an action.
*/
callbackFromNative: function(callbackId, isSuccess, status, args, keepCallback) {
try {
var callback = cordova.callbacks[callbackId];
if (callback) {
if (isSuccess && status == cordova.callbackStatus.OK) {
callback.success && callback.success.apply(null, args);
} else if (!isSuccess) {
callback.fail && callback.fail.apply(null, args);
}
/*
else
Note, this case is intentionally not caught.
this can happen if isSuccess is true, but callbackStatus is NO_RESULT
which is used to remove a callback from the list without calling the callbacks
typically keepCallback is false in this case
*/
// Clear callback if not expecting any more results
if (!keepCallback) {
delete cordova.callbacks[callbackId];
}
}
}
catch (err) {
var msg = "Error in " + (isSuccess ? "Success" : "Error") + " callbackId: " + callbackId + " : " + err;
console && console.log && console.log(msg);
cordova.fireWindowEvent("cordovacallbackerror", { 'message': msg });
throw err;
}
},
addConstructor: function(func) {
channel.onCordovaReady.subscribe(function() {
try {
func();
} catch(e) {
console.log("Failed to run constructor: " + e);
}
});
}
};
module.exports = cordova;
最佳答案
你必须先安装cordova-plugin-device
cordova 插件添加 cordova-plugin-device
然后你可以使用device.uuid
或者设备对象的任何其他属性
关于javascript - 询问有关 cordova device.uuid javascript 的信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40169000/
我试图再次将反射的 UUID 转换回实际的 UUID 对象,但找不到方法,当我打印反射值时它看起来是正确的,但在尝试转换时我找不到方法。 package main import ( "fmt"
我想知道 UUID 是否是唯一的,即使它们是在不同的系统上生成的,这些系统可能采用不同的算法。例如,如果您在 MySQL 和 .Net 中生成了一堆 UUID,碰撞的可能性会更高,还是所有系统都使用完
是否可以一个接一个地创建两个重复的 UUID?我不熟悉 UUID 是如何生成的,但我猜想如果您在同一毫秒内从同一 MAC 地址创建了两个单独的 UUID,那么它们将完全相同。这是真的吗? 我想我是在问
当我使用 python uuid 模块中的 UUID() 函数检查我们的测试 uuid 之一时,我遇到了这种奇怪的行为。 从 uuid 导入 UUID uuid1 = UUID('00000000-0
开始使用 java.util.UUID。我的问题是如果我有两个 UUID 变量,比如 u1 和 u2,并且我想检查它们是否相等,我可以安全地使用表达式 u1 == u2 还是必须编写 u1 .equa
我浏览了 python UUID 模块的文档。 >>> uuid.uuid4() UUID('82fe5629-6680-4b13-a4e3-7a082f10e038') >>> uuid.uuid4
我正在创建一个程序,我在其中大量使用 UUID 来识别用户和组等内容。鉴于 UUID 已经被占用的可能性极低,我是否应该担心发生碰撞的可能性? 最佳答案 这在很大程度上取决于 A)您的要求 B)底层实
您应该使用哪个版本的 UUID?我看到很多帖子解释了每个版本的含义,但我很难弄清楚什么最适合哪些应用程序。 最佳答案 有两种不同的方式生成 UUID。 如果您只需要一个唯一 ID,则需要版本 1 或版
我知道我们可以轻松提取 uuid 版本号。有没有可靠的方法来提取时间戳、MAC 地址等信息? 谢谢! 最佳答案 符合标准的 UUID 可能是多种变体之一,它看起来像这样: AAAAAAAA-BBBB-
我可以干净地使用私有(private) UUID 变体/版本吗? 我使用我基本上认为是大整数的随机 UUID。现在,我想生成一个“私有(private)”UUID,它不基于众所周知的 5 个变体/版本
我已阅读 man 页面,但我不明白 name 和 namespace 的用途。 For version 3 and version 5 UUIDs the additional command lin
我目前正在项目中使用 boost::uuids::uuid,并且我想序列化包含 boost::uuids::uuid 的对象。我尝试了下面的简单示例,但出现错误: /usr/include/boost
我正在使用 Datastax Java 驱动程序在 Cassandra 数据库中执行基本的插入语句。我的主键列是uuid类型。从我在官方文档中看到的,在 Cassandra 中调用 uuid() 函数
会抛出异常吗? UUID() 是否会悄无声息地失败?是否有任何情况下“myStatus”来自 myStatus = True myUUID = uuid.UUID( someWeirdValue )
在我的 Android 应用程序中,我有这种采用 UUID 的方法。不幸的是,当我这样做时: OverviewEvent overviewevent = eventAdapter.getOvervie
我有一个简单的 mongo 迁移框架,它正在执行一些传递给它的脚本。 现在我想将我的 LUUID 迁移到 UUID。我写了以下内容: function fixIds(collectionName) {
我有一个非常奇怪的问题是我得到一个有效的 UUID 不是一个有效的 UUID,例如: 'fd31b6b5-325d-4b65-b496-d7e4d16c8a93' is not a valid UUI
我正在测试 Goa对于一个 API。我想使用 uuid 作为 ID 数据类型。我在 controller.go 中修改了以下函数: // Show runs the show action. func
我有一个包含 uuid 和系统列的表。我需要一个查询来仅返回具有 system=1 的 uuid,而不返回具有 system= 1 和 2 的 uuid 最佳答案 SELECT * FROM
我很想了解在 Avro 中编码一种非常特定类型的数据的最佳实践:UUID。 最佳答案 到目前为止,我发现的唯一方法是定义自定义 UUID: { "namespace" : "your.namesp
我是一名优秀的程序员,十分优秀!