为什么我们在AVCam示例代码中获取AVCaptureSessionInterruptionReasonKey的地址? [英] Why do we get the address of AVCaptureSessionInterruptionReasonKey in AVCam sample code?

查看:167
本文介绍了为什么我们在AVCam示例代码中获取AVCaptureSessionInterruptionReasonKey的地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读此示例代码( AVCam 关于AVCaptureSession等等。我注意到以下这一行(代码链接):

I am reading this sample code (AVCam) about AVCaptureSession and etc. And I notice this following line (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中):

The comment in the code make sense. But what doesn't make sense to me is why do we want to get the address of AVCaptureSessionInterruptionReasonKey. It is defined as the following (in AVCaptureSection.h):

AVF_EXPORT NSString *const AVCaptureSessionInterruptionReasonKey NS_AVAILABLE_IOS(9_0);

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

If the key is defined, how will its address be nil? If this key is not defined, the code will never be compiled, right? Could someone explain to me how this if statement work?

推荐答案

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

AVCaptureSessionInterruptionReasonKey was added in iOS 9.0. Such an if statement is needed only if your app also supports iOS 8 or earlier.

运行代码时在iOS 9或更高版本的设备上,该值将为非零,而 if 语句将为true。在iOS 8或更早版本的设备上,值为 nil 如果语句为false。

When the code is run on a device with iOS 9 or later, the value will be non-nil and the if statement will be true. On devices with iOS 8 or earlier, the value will be nil and the if statement will be false.

如果您的应用仅支持iOS 9或更高版本,则无需 if 声明。

If your app only supports iOS 9 or later, there is no need for the if statement.

阅读 SDK兼容性指南

这篇关于为什么我们在AVCam示例代码中获取AVCaptureSessionInterruptionReasonKey的地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆