GyWxappCases icon indicating copy to clipboard operation
GyWxappCases copied to clipboard

iPhone真机生成uuid报错

Open aslanTT opened this issue 6 years ago • 3 comments

var uuidTool = require('/utils/node-uuid/uuid.modified.js'); uuid = uuidTool.v4(); screen shot 2018-03-19 at 7 36 59 pm

aslanTT avatar Mar 19 '18 11:03 aslanTT

安卓也无法生成。 原因: uuid 依赖于crypto,crypto 已不支持单独引用,内置在运行环境中(如node或者浏览器),而手机上是没有这个环境的

byg avatar May 03 '18 06:05 byg

好吧那只好放弃用这个库了,谢谢 @byg

aslanTT avatar May 03 '18 06:05 aslanTT

提供一个算法:

/**
 * Returns a v4 compliant UUID.
 *
 * @returns {string}
 */
export default function uuid() {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        const r = (Math.random() * 16) | 0,
            v = c === 'x' ? r : (r & 0x3) | 0x8;
        return v.toString(16);
    });
}

byg avatar May 04 '18 03:05 byg