Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iPhone真机生成uuid报错 #1

Open
aslanTT opened this issue Mar 19, 2018 · 3 comments
Open

iPhone真机生成uuid报错 #1

aslanTT opened this issue Mar 19, 2018 · 3 comments

Comments

@aslanTT
Copy link

aslanTT commented Mar 19, 2018

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

@byg
Copy link

byg commented May 3, 2018

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

@aslanTT
Copy link
Author

aslanTT commented May 3, 2018

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

@byg
Copy link

byg commented May 4, 2018

提供一个算法:

/**
 * 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);
    });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants