gpt4 book ai didi

iphone - iPhone 上的弱链接无法正常工作

转载 作者:太空狗 更新时间:2023-10-30 03:14:08 25 4
gpt4 key购买 nike

我有一个主要针对 3.0 的 iPhone 应用程序,但它在更新的 API 可用时利用了它们。代码是这样的:

if (UIApplicationDidEnterBackgroundNotification != NULL) {
[nc
addObserver: self
selector: @selector(irrelevantCallbackName:)
name: UIApplicationDidEnterBackgroundNotification
object: nil];
}

现在,根据 Apple 所说的一切,如果相关 API 是弱链接,那将正常工作,因为动态链接器会将 UIApplicationDidEnterBackgroundNotification 评估为 NULL。除了它没有。应用程序编译,但一旦它命中 if (UIApplicationDidEnterBackgroundNotification != NULL),它就会崩溃并显示 EXC_BAD_ACCESS

这仅仅是我需要设置的编译器标志的问题吗?还是我的做法有误?

最佳答案

Aa 我想通了。对于不是函数的符号(例如 extern const int foobar),您必须比较符号的地址,而不是符号本身,因此:

if (&UIApplicationWillEnterForegroundNotification != NULL)
etc;

回想起来这有点明显,但我仍然责怪我周围的整个宇宙从未提及这种区别。

关于iphone - iPhone 上的弱链接无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3002833/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com