gpt4 book ai didi

ios - 为什么我们会在 AVCam 示例代码中获取 AVCaptureSessionInterruptionReasonKey 的地址?

转载 作者:行者123 更新时间:2023-12-01 18:48:44 26 4
gpt4 key购买 nike

我正在阅读有关 AVCaptureSession 等的示例代码( AVCam )。我注意到以下行( link to the code ):

// In iOS 9 and later, the userInfo dictionary contains information
// on why the session was interrupted.
if ( &AVCaptureSessionInterruptionReasonKey ) {
...
}

代码中的注释是有意义的。但是对我来说没有意义的是为什么我们要获取 AVCaptureSessionInterruptionReasonKey 的地址.它定义如下(在 AVCaptureSection.h 中):
AVF_EXPORT NSString *const AVCaptureSessionInterruptionReasonKey NS_AVAILABLE_IOS(9_0);

如果定义了key,它的地址将如何 nil ?如果没有定义这个键,代码永远不会被编译,对吧?有人可以向我解释一下这个 if 语句是如何工作的吗?

最佳答案

AVCaptureSessionInterruptionReasonKey在 iOS 9.0 中添加。这样的if仅当您的应用还支持 iOS 8 或更早版本时才需要声明。

当代码在 iOS 9 或更高版本的设备上运行时,该值将是非 nil 并且 if陈述将是真实的。在装有 iOS 8 或更早版本的设备上,该值为 nilif声明将是错误的。

如果您的应用仅支持 iOS 9 或更高版本,则不需要 if陈述。

阅读 SDK Compatibility Guide在 iOS 文档中了解有关此类检查的更多详细信息。

关于ios - 为什么我们会在 AVCam 示例代码中获取 AVCaptureSessionInterruptionReasonKey 的地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32876932/

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