可可 arc4random OS X 10.6

发布于 2024-12-14 07:56:39 字数 205 浏览 1 评论 0原文

我为 Lion 创建了一个简单的自定义视图应用程序。现在有朋友用Snow Leopard测试了一下,无法启动。可悲的是我没有例外。我唯一知道的是,这是关于 arc4random 的函数调用,这在她的版本中不可用。 我实际上无法想象,Lion 中引入了如此重要的功能(是的,我对可可相当陌生......),所以你们知道这可能是什么吗? 我会尝试获取异常详细信息,但我几乎处于时间压力之下......

I have created a simple Custom View Application for Lion. Now a friend tested it using Snow Leopard and couldn't launch it. Sadly I don't have the Exception. The only thing I know is, that it's about the function-call of arc4random, which is not available in her version.
I actually can't imagine, that such an essential function was introduced in Lion (yeah, im rather new to cocoa...), so do you guys have any idea, what that could be about?
I'll try to get the Exception Details, but I am pretty much under time pressure...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瀞厅☆埖开 2024-12-21 07:56:39

我的应用程序在 Snow Leopard 上崩溃时遇到了类似的问题,崩溃报告显示:

Dyld Error Message:
Symbol not found: _arc4random_buf
Referenced from: <myApp binary>
Expected in: /usr/lib/libSystem.B.dylib

我必须阅读 文档 多次,直到我意识到 arc4random() 本身从 10.4 开始就可用,但是arc4random_buf() 仅自 10.7 起可用。如果您使用 arc4random_buf() 函数(像我一样),它将无法在 10.6 上运行。

因此,我只是用以下 C 代码替换了 arc4random_buf() 函数:

void myArc4RandBuf(uint8_t* randomBytes, size_t length) {
    size_t intBufLength = (length/4)+1;
    uint32_t randomInts[intBufLength];        
    for (int i = 0; i < intBufLength; i++) {
        randomInts[i] = arc4random();
    }
    memcpy(randomBytes, randomInts, length);
}

这可能会慢一点,因为 arc4random() 被调用了几次,但它可以工作从 10.4 到 10.8 的所有 Mac 操作系统。

I just had a similar problem with my app crashing on Snow Leopard with the crash report saying:

Dyld Error Message:
Symbol not found: _arc4random_buf
Referenced from: <myApp binary>
Expected in: /usr/lib/libSystem.B.dylib

I had to read the documentation several times until I realized that arc4random() itself is available since 10.4 but arc4random_buf() is only available since 10.7. If you use the arc4random_buf() function (like me) it will not run on 10.6.

So, I just replaced the arc4random_buf() function with the following C-code:

void myArc4RandBuf(uint8_t* randomBytes, size_t length) {
    size_t intBufLength = (length/4)+1;
    uint32_t randomInts[intBufLength];        
    for (int i = 0; i < intBufLength; i++) {
        randomInts[i] = arc4random();
    }
    memcpy(randomBytes, randomInts, length);
}

That is probably a bit slower because arc4random() is called several times, but it works on every Mac OS from 10.4 to 10.8.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文