WWDC2019--Core Bluetooth 新功能

在iOS13当中,针对CoreBluetooth有一些更新,最劲爆的就是支持音频了,也就是iOS的开发者也可以搞经典蓝牙啦。

对开发者影响最直接的就是那个隐私设置,info.plist里面加字段,你敢不加它就敢闪退。。。

贴一下这一篇的地址, 可以用developer那个App观看,就是对网络要求比较高,有时候很卡看不了,而且下载之后官方的翻译会出不来,希望2020年的时候Apple能够改善这一块。


以下是这一篇的翻译,基于我自己对CoreBluetooth的理解用中文表达了它。

Thank you for joining the session. My name is Duy Phan. I'm here with Yilok and Meghna to talk to you about what's new in Core Bluetooth. I'll start with an introduction.

谢谢你们来参加这个专题。我是Duy Phan,在这里我将和Yilok、Meghna一起为大家演示Core Bluetooth上的新变化。首先会从概要开始,

Then LE 2 Mbps and advertising extension. Then provide an overview for Core Bluetooth for BR/EDR devices. Then Core Bluetooth for dual-mode, user privacy, developer tools, then wrap up with a summary.

然后会谈到LE 2 Mbps(高速)和扩展广告。还有 CoreBluetooth 对于 BR/EDR 的使用,还有双模蓝牙通讯用户隐私开发者工具方面的情况。最后会总结一下。

Let's start with the introduction. For those in the audience that's new to Core Bluetooth, the Core Bluetooth framework is our abstraction of the Bluetooth low energy specification and hardware. We provide our developers an easy and robust way to develop applications that can interact with Bluetooth low energy devices, and since the introduction of the framework, we've seen an amazing number of accessories and applications. We've seen everything from health and fitness devices to indoor locationing and item finding to creative tools, toys and accessories for kids, things for the home, appliances, and even everyday items like Bluetooth controlled water bottles and mugs. Our developers' creativity and hard work have really made the Bluetooth low everything ecosystem a very vibrant and innovative space, thank you.

让我们从简介开始吧。有些朋友可能对于 Core Bluetooth 不太熟悉,这里我简单介绍下,Core Bluetooth 框架是我们对Bluetooth低功耗规范和硬件的抽象。我们为开发者们提供了一种简单而强大的方法用于开发和低功耗(BLE)蓝牙设备交互的应用程序。自从引入此框架以来,已经涌现出了非常多的配件和应用程序。从健康和健身设备到室内定位和物品查找工具,再到创意工具,儿童玩具和配件,家庭用品,家用电器,甚至是日常用品(如蓝牙控制的水瓶和马克杯),感觉所有东西都可以和蓝牙联系起来。谢谢你们,开发人员的创造力和辛勤工作确实使Bluetooth Low Everything【BLE的真实说法是Bluetooth Low Energy,这里应该是用了个小幽默】生态系统成为了一个充满活力和创新的空间。

But there's more. There exists an entire class of Bluetooth devices that are also thriving and growing, but we often don't talk about them here because they don't support the Core Bluetooth framework. These are Bluetooth BR/EDR devices, and they include accessories like your favorite audio streaming devices, in-car entertainment systems with hands-free calling and various accessories like mouse and keyboards and game pads. What's been missing is a way for our Core Bluetooth developers to develop applications that can interact with these devices. Until now.

但只有这些我们就满足了吗?【当然不满足,看看隔壁安卓的功能还有哪些俺们做不到的,今年就解决它】。有一整类蓝牙设备也在蓬勃发展,但由于它们不支持 Core Bluetooth 框架,通常我们不在这里谈论它们。那就是蓝牙 BR/EDR 设备,例如你们最喜欢的音频流设备,具有免提通话功能的车载娱乐系统,以及各种各样的鼠标、键盘以及游戏手柄等配件。我们的 Core Bluetooth 开发者所缺少的是一种可以与这些设备进行交互的应用程序的方式。但是现在【转折停顿,重点来了】,

This year we are adding Core Bluetooth support for BR/EDR devices.

今年,我们为 Core Bluetooth 增加了对 BR/EDR 设备的支持。【此处应有

Thank you. This means that Core Bluetooth can now reach out and interact with all of your favorite Bluetooth devices regardless of what transport they run. In addition, we added various dual-mode features, so the two transport works even better when they're together. We hope that our developers will take advantage of these features, and we look forward to seeing all of the new accessories and applications you build.

谢谢。这意味着 Core Bluetooth 现在可以与你的所有蓝牙设备进行交互,不管它们运行什么传输方式,BLE或者BR/EDR都可以。此外,我们添加了各种双模式功能,让同时使用两个传输时的效果更好。我们希望使用 CoreBluetooth 的你们能够利用这些功能,并期待看到你们创造出新的外设和应用程序。

So, this year we really have three major driving themes. The first is, as always, to improve our core technology but also to protect our user privacy and enable our developers with better tools. Let's get started with improvements to our core technology and LE 2 megabits. LE 2 Mbps is a new feature in Bluetooth 5.0.

因此,今年我们确实有三个核心主题。一如既往,既要改善我们的核心技术,又要保护我们的用户隐私并为我们的开发人员提供更好的工具。让我们从核心技术的改进和LE 2 Mbps说起,LE 2 Mbps是蓝牙5.0中的一项新功能,

The physical layer rate or radio rate can increase now from 1 to 2 Mbps between compatible devices. This means that with the same amount of airtime, Core Bluetooth can now transmit twice the number of bits, so your connections are not only faster, they're also more power efficient. This is better yet transparent to the application. We will handle all of the link layer negotiations for you based on the platform you're on. But remember, if you're developing an accessory, your accessory must also support LE 2 Mbps for this to work. This is available now starting with iPhone 8, 8 Plus, iPhone X, Apple TV 4K, and the Apple Watch Series 4.

兼容设备之间的物理层速率或无线电速率现在可以从1 Mbps增加到2 Mbps。 这意味着在相同的通话时间下,Core Bluetooth 现在可以传输两倍的数据量,因此你的连接不仅速度更快,而且功效更高。我们将根据你使用的平台为你处理所有链接层的协议障碍,所以这对应用程序来说更加透明。但是请记住,如果你正在配合外设开发产品,那么你的外设也必须支持 LE 2 Mbps 才能正常享受这个速度提升的好处。目前这个功能在 iPhone 8、8 Plus,iPhone X,Apple TV 4K和Apple Watch Series 4 及以上设备支持。

And here I have an illustration of Bluetooth 1 Mbps in various modes.

我曾经在这个舞台上以各种模式展示过Bluetooth 1 Mbps。

And I've added LE 2 Mbps to show the [applause], thank you, to show the leap forward in performance. Also new for this year we've added advertising extension.第10段

今天,让我把 LE 2 Mbps 也加上【啥也别说了,】。谢谢,看看这性能的飞跃。另外,我们在今年的新功能里还添加了广告扩展【Advertising extension 】。

Advertising extension is a Bluetooth 5.0 feature. It essentially improves upon three main points for advertising. The first is it eases the congestion on the three advertising channel by sending a smaller payload on the advertising channel, then jumping to the more spacious data channel to transmit a much larger payload. Up now from 31 to 255 bytes, and the transmission rate itself can now be in LE 2 Mbps. Core Bluetooth will support extended scan this year.

广告扩展是蓝牙5.0的功能。它从本质上改进了广告的三个主要方面。首先,它通过在广告频道上发送较小的有效负载,然后跳转到更宽敞的数据通道以传输更大的有效负载,来缓解三个广告频道上的拥塞。现在从31字节增加到255字节,传输速率本身现在可以达到 LE 2 Mbps。Core Bluetooth 将在今年[2019]支持扩展扫描。

This means that we can scan now for the extended advertisements that I've just mentioned, but we will only scan for our extended advertisements that are transmitted in LE 2 Mbps.

这意味着我们现在可以扫描我刚才提到的扩展广告,但是我们将仅扫描以LE 2 Mbps传输的扩展广告。

So, if you're developing an accessory, your accessory must also support extended advertisement with LE 2 Mbps. We now support extended advertisement payloads up to 124 bytes. This is four times the amount of advertisement data that an accessory can send us today. This is again transparent to your application.

因此,如果你要开发外设,它也必须支持LE 2 Mbps的扩展广告。现在,我们支持扩展的广告有效载荷,最大可达124个字节。这是升级前外设可以发送给我们的广告数据量的四倍,这些对于app来说也很好理解。

You can use the same scan API, scan filters. We would scan for both legacy and extended advertisements. There's a new API for you to programmatically query for platform support, and this is now supported on iPhone XS and the new iPad Pro.

你可以使用相同的扫描API,即扫描过滤器。我们将同时扫描旧广告和扩展广告。有一个新的API让你可以在代码里查询平台的支持情况,目前在iPhone XS和新的iPad Pro上已经支持。

Also new for this year we're going to support extended connections.

在今年的新功能中,我们还增加了扩展连接的支持。

This means that we can make connections to connectable, extended advertisements.

这意味着我们可以与可连接的扩展广告建立连接。

Extended connections improve upon the existing connection exchange protocol, and I'll explain how. Today with Legacy Connections, the advertiser would advertise a connectable advertisement. The scanner would send a connection identification if it wants to connect. There's no ACK for this. The scanner assumes that the connection indication reaches the advertiser. It then wakes up the host processor to tell it there's a new connection. But the connection indication may actually not reach the advertiser because the RF characteristic of the scanner and advertiser can differ, and the RF environment is very dynamic.

扩展连接对现有的连接交换协议进行了改进,接下来我会解释怎么做。如今,借助旧版连接,广告者【外设】可以投放可连接的广告。如果扫描者【中心】想要连接,它将发送连接标识。这里不需要 ACK。扫描程序假定连接指示已到达广告者。然后,它将唤醒主机处理器以告知它存在新的连接。但是连接指示实际上可能未到达广告者,因为扫描者和广告者的RF特性可能不同,并且RF环境非常动态。

So, because of this, throughout your day, your whole processor can be unnecessarily woken up, training your phone's battery more while you're using, your user is using your application or accessory. But extended connections improve upon this.

目前的情况下,用户使用你的的应用和外设时,你的处理器在一整天之内可能会被无数次不必要的唤醒,这对电池是一个额外的消化,扩展链接恰好可以改善这一点。

With extended connections, the advertiser would advertise a connectable extended advertisement. The scanner would send a connection request.

通过扩展连接,广告者将发布可连接的扩展广告。扫描者将发送连接请求。

The advertiser would send an explicit connection response, and only when the scanner receives this connection response it will wake the host processor to tell it there's the new connection. In addition, your connection can also start in LE 2 Mbps, skipping some of the link layer negotiation. And because of this, extended Connection is more robust and power efficient. It is again transparent to your application if you can call the same connect API. It will connect to both Legacy and Extended Advertisements. But remember if you're developing an accessory, your accessory must also support connectable extended advertisements.第20段

广告者会发送连接应答,只有当扫描者准确接收到这个应答之后才会唤醒主处理器告诉它这是一个新的连接。此外,你的连接也可以LE 2 Mbps的速度开始,从而跳过了一些链路层的验证。因此,扩展连接更加健壮和省电【对比扩展广告】。你可以调用相同的连接API,这对你的App来说也没什么大的负担。它将同时保持旧的连接和扩展广告的连接,但是有一点请记住,如果你是在开发外设,你的外设也必须要支持可连接的扩展广告。

There's a new API for you to programmatically query for platform support.

同样这里也有一个新的API,提供给你以编程方式查询平台支持情况。【CBCentralManagerd第117行supportsFeatures in swift

This is also available now with iPhone XS and the new iPad Pro. I'd like to now hand it off to Yilok to talk about Core Bluetooth support for BR/EDR. Thank you.

目前在 iPhone XS 和新版 iPad Pro 上已经支持。 接下来将由 Yilok 为大家介绍Core Bluetooth 支持 BR/EDR 的情况

Thanks, Duy. Hi everyone.

谢谢Duy,大家好。

I'm Yilok, and I'm here to introduce you to you the new things we've added to Core Bluetooth for BR/EDR devices. When we first introduced Core Bluetooth back in 2012, we wanted to create an abstraction layer for you to use what's called GATT.

我是Yilok。接下来我将给大家介绍我们为 Core Bluetooth 新增的关于 BR/EDR 设备支持的情况。在2012年我们第一次介绍 Core Bluetooth 时,当时我们是想创造一个可以调用GATT的抽象层。

Now GATT is a Bluetooth SIG protocol that is hierarchy-based, and it consists if services and characteristics, and it makes it very easy to read, write, and be notified of changes on these characteristics. You've shown us that it's exceptionally easy to make great products such as heart rate monitors, toys, and a bunch of accessories in the world. And it's been wonderful seeing what you've been able to do with the Core Bluetooth apps that you build to interface with these accessories.

GATT现在是一种基于层次结构的 Bluetooth SIG 协议,它由服务和特征组成,并且可以很容易地读取,写入和通知这些特征的更改。你们已经向我们展示了可以非常容易地通过它制造出出色的产品(例如心率监测器,玩具和世界上许多配件)。能够看到你们通过构建的Core Bluetooth应用程序与这些配件建立接口创造出来的东西,真是太棒了。【商业吹捧,不必细究

Now, this year, as Duy has mentioned, we're adding support for Core Bluetooth over BR/EDR devices or classic devices. Now these devices range from things such as car head units, speakers, and headphones. So, how do we do this? Well, our stack from last year consisted of two different transports. Essentially, we were running the system profiles or things such as audio, A2DP, HFP, and remote-control profiles in the system. On the other side, for low energy, we were running Core Bluetooth over GATT, and that was the framework that you were using to interface with your accessories. This year, we've merged the two layers together, and now, you have transparent access to both BR/EDR and low energy without doing anything.

今年,就像Duy刚刚提到的,我们为 Core Bluetooth 增加了 BR/EDR 设备(或者称之为经典蓝牙设备)的支持。现在,这些设备的范围很广,例如汽车音响,扬声器和耳机。那么我们是如何实现对这些设备的支持的呢?让我们来看一下,之前我们的堆栈由两种不同的运输方式组成。本质上,我们是在系统中运行系统概要文件或其他诸如音频,A2DP,HFP和远程控制概要文件之类的东西。在LE这边,我们在GATT之上运行了 Core Bluetooth ,也就是你们用来和外设通信的框架。今年,我们把这两层合并在一起,现在你无需做任何事情就可以直接使用 BR/EDR 和 LE 两种通道。

Now, what this means for you is without much changes in the API, you can now work with both the classic devices and the low energy devices. So let's go and look into the details of Core Bluetooth for BR/EDR. This now will allow transparent use of GATT with the BR/EDR devices. It's still running the exact same Bluetooth SIG protocol. There's no changes to that, and so you can look at this specification online on the Bluetooth SIG website. To your application and to the developer, the CBPeripheral APIs are exactly the same. You can still do the same service discovery and be notified of changes to characteristics.

对你而言,这意味着你不需要修改很多的API就可以同时使用 LE 设备和经典蓝牙设备。接下来让我们看看 Core Bluetooth 支持 BR/EDR 的一些细节。现在,这将允许在 BR/EDR 设备中直接使用 GATT,它仍在运行完全相同的 Bluetooth SIG 协议,对此没有任何更改,因此你可以在 Bluetooth SIG 网站上在线查看此规范。对于你的应用程序和开发人员而言,CBPeripheral API 完全相同,你仍然可以执行相同的服务发现,并收到有关特性更改的通知。

There is a new change in the CBCentralManager. We've added a way for you to be notified when a device is connected with a service UUID or a known peripheral UUID.

在 CBCentralManager 这边有一点点变化。当设备与服务UUID或已知的外围设备UUID连接时,我们添加了一种通知方式,

And I'll go more into detail about that later. Core Bluetooth for BR/EDR is available with iOS 13, the watchOS, and tvOS that we released this week.

后面我们会详细介绍它。Core Bluetooth 将在iOS13版本支持 BR/EDR,本周同期发布的 watchOS 和 tvOS 也会支持。

And finally, because GATT is a software layer protocol, you can add support to your accessory without the need for new hardware. This means only a software or firmware update. Now let's look at the new API. To register for connection events, you'll register by either a known service or a known peripheral UID.第30段

最后提一点,由于 GATT 是软件层协议,因此你不需要添加任何新的硬件的情况下就可以在外设上支持它。仅仅需要更新下软件/固件就可以了。现在让我们看看这个新的API,要注册连接事件,你需要通过已知服务或已知外围UID进行注册。

This would be akin to something like the heart rate service. You'll call registerForConnectionEvents, and you'll pass to the CBCentralManager a type for either a service UID or a peripheral UID. When we find a matching option, we'll send you a delegate callback, and this delegate callback will include the CB peripheral and the type of connection event. It's pretty simple.

类似于心率服务。你可以调用 registerForConnectionEvents,并且向 CBCentralManager 传递一个服务UID或者外设UID的类型。当我们(CoreBluetooth)发现了符合目标的设备,我们会通过一个delegate回调方法返回给你,这个回调函数同时会将这个外设和连接事件类型返回给你,这很好理解。

So, what does the incoming connection look like from your app's point of view? Your app will have instantiated a CBCentralManager, passed us a known service UID, and in the case of a BR/EDR or classic device, your user will go to the Bluetooth settings and search for the device, in this case let's say it's a headset running heart rate.

从你的应用角度看,这个连接是什么样子的呢?你的App将实例化一个CBCentralManager,并向我们传入一个服务UID,对于经典蓝牙(BR/EDR)设备而言,你的用户将进入系统蓝牙设置并搜索该设备,现在让我们假设它是个支持心率的耳机。

They'll discover the device, find it, and attempt to connect. Pairing will be triggered, and then afterwards when we're connected, we'll run a service discovery of the GATT services.

接下来会搜索设备,找到它,用户点击连接,这将促发配对弹框,当连接建立之后,我们会发起GATT服务的搜索。

If we find a service that you want, then you'll get the delegate callback.

如果我们找到了想要的服务,你将会从delegate回调方法中得到它。

And this will now look extremely similar to those who have already used Core Bluetooth.

这过程看起来与目前使用 Core Bluetooth 的情形极为相似。

With your delegate callback, you'll then handle the connection event, and so you might call connect on that given peripheral. So, all this code looks like so.

在你的delegate回调方法里,你可以处理连接事件,你很有可能会调用连接方法去连接这个周边设备。现在,所有代码看起来都差不多【和BLE情况】,

You'll do initialization first, register for your connection event with the CBCentralManager, and finally handle the delegate callback. If you're interested in the device, call connect, and then you can clear the registration for filters.

首先你需要进行初始化,使用CBCentralManager注册连接事件,最后处理委托回调。如果回调函数中的设备是你想要的,调用connect,然后你可以清除过滤器的注册。

Now, what about outgoing connections. Let's say you have a known peripheral already and you're paired to it and you want to connect.

现在,传出连接又如何呢?我们说这里已经有一个你知道的已经和系统配对了并且是你想连接的周边设备。

You can now connect out to a BR/EDR device. To do so, you'll do the same thing, instantiate your CBCentralManager and call connect.

你现在可以连接到 BR/EDR 设备,做到这一点,和前面一样,你只需要实例化 CBCentralManager 对象并且调用连接函数就好。

This is not a new API. This has existed in CBCentralManager for a while now. And so if you're calling connect on a BR/EDR device, if your app is in foreground, then we'll try to make a connection out to that device for you.第40段

这不是新的API,它已经存在于 CBCentralManager 中已有一段时间了。 因此,如果你在 BR/EDR 设备上调用connect,而且你的应用程序处于前台,我们将尝试为你建立与该设备的连接。

We'll page the device, and if it's connected, then you'll get a delegate callback.

我们将寻呼设备,如果连接已经完成,你将会得到一个delegate的回调函数。

It's that simple. So, now that we've gone through the new APIs for BR/EDR devices, let's continue on to the other improvements we've made for Core Bluetooth dual-mode.

就这么简单。因此,既然我们已经了解了适用于 BR/EDR 设备的新API,那么让我们继续讨论针对 Core Bluetooth 双模所做的其他改进。

This means when you're using low energy and BR/EDR together. One common thing we've seen with dual-mode devices, as you've developed more and more accessories and apps on top of it, is that generally when users use your device, they see two entries in the Bluetooth settings. There's a low energy one, and there's a BR/EDR or classic one.

这意味着当你一起使用 LE 和 BR/EDR 设备时,当你在双模设备上开发越来越多的附件和应用程序时,我们已经看到的一件事是,通常,当用户使用你的设备时,他们会在蓝牙设置中看到两个条目。一个是 LE 的,一个是经典蓝牙的。

And it's sometimes confusing to users. So, we worked really hard this year to alleviate this confusion. So, this year we're introducing adoption of what's called Cross Transport Key Derivation. This is a Bluetooth 4.2 SIG specification, and basically what this means is through a single pairing we will derive link keys for the other transport. To you, it means that the device will now have a single CBPeripheral identifier, so you don't need to care about the transport of the device. This is completely transparent to your application, and now that we have the single pairing for two devices, it means your app can seamlessly use both low energy and BR/EDR together. So before when users of your device or application, if they were seeing two devices, now they'll just see one, which is merged.

这是一件让用户困惑的事,因此,我们今年努力解决这个问题【这也很苹果】。今年我们将引入所谓的“交叉传输密钥派生”【Cross Transport Key Derivation】。这是蓝牙4.2 SIG规范,基本上,这意味着通过单对配对,我们将导出其他传输的链接密钥。对你而言,这意味着设备现在只有一个 CBPeripheral 的标示符,因此你不需要考虑传输通道的问题。现在我们可以将两个设备配对使用,这意味着你的应用程序可以无缝地同时使用 LE 和 BR/EDR,这对于你的应用程序是完全透明的。因此,用户在使用你的设备或应用程序时,以前看到两个设备,现在他们只会看到一个已合并的设备。【别说了,】

Thank you. And we can further take advantage of Cross Transport Key Derivation, or CTKD, to improve the pairing process.

谢谢【回应上一段结束时的】。而且,我们可以进一步利用“交叉传输密钥派生”(CTKD)来改善配对过程。

So let's say you want to control the entire discovery and pairing experience for your user.

假设你要控制用户的整个发现和配对过程的体验。

Instead of having the user go into Bluetooth settings and do an inquiry scan, which leaves your app experience, you can now look for low energy advertisements from your accessory. If you find the device, you can then Call Connect and connect over LE and access the protective characteristic. Once you're paired, because of CTKD, we'll take the LE key, and we'll also derive the BR/EDR key.

无需让用户进入系统蓝牙设置并进行查询扫描(这会降低你的应用程序体验),而是可以从外设中搜索 LE 设备的广告。如果找到该设备,则可以调用连接通过 LE 连接并访问保护特性。完成配对之后,由于有了CTKD,我们将获得 LE 键,并且还将获得 BR/EDR 键。

And this means you can now make a BR/EDR connection without having to trigger more pairing to confuse the user, and it stays in the app for the entire experience.

这意味着你在创建 BR/EDR 连接时不需要促发更多的配对让用户懵逼,整个过程都可以在你的App中完成。

Great. Now that we've talked about improving pairing, let's talk about how we improve dual-mode connections. Let's consider a new product that you want to plan, and it's a home audio device. And it would be great if your user could be using your app and have it trigger some sort of connection to use media, such as music or podcast when the user becomes in proximity of the device. So, you'd want the user to bring up something like music or podcasts, which this would mean that iOS would have to bring up what's called a BR/EDR channels for you. We've done so this year by introducing a new concept called bridging. Bridging works by taking advantage of low energy proximity to bring up BR/EDR profiles such as A2DP, HFP, AVRCP. This will work on all devices that support CTKD and to take advantage of it in your application, it's extremely easy.

这很棒。既然我们已经讨论了改善配对,那么我们来谈谈如何改善双模连接。让我们假设一个你计划开发一款新产品,它是一种家用音频设备,如果用户可以使用你的应用,并且当用户靠近设备时触发某种连接以使用媒体(例如音乐或播客),这功能看起来很棒吧。我们看看咋做,你希望用户带来诸如音乐或播客之类的东西,这意味着iOS必须为你带来所谓的 BR/EDR 频道。今年,我们通过引入一种称为桥接的新概念来做到这一点。通过利用 LE 的接近度和建立 BR/EDR 配置文件(例如A2DP,HFP和AVRCP)来进行桥接。这将在所有支持CTKD的设备上运行,你可以非常容易的在应用程序中使用它。

You'll use a new key in the CBManagerConnect, and it's called the TransportBridgingKey.第50段

你将需要在 CBManagerConnect 中使用一个新的键: TransportBridgingKey

You add it in the option dictionary. And so when you pass that to us, we'll try to connect over low energy to your device. If we find it, then we'll immediately page out over BR/EDR and connect as many profiles as we can.

把它添加到可选字典里。当你把它作为参数传给我们【CoreBluetooth】时,我们将尝试通过 LE 连接到你的设备。如果我们找到了它,那么我们将立即通过 BR/EDR 调出页面并连接尽可能多的配置文件。

The result is that your user can now seamlessly use all the multimedia profiles without having to do anything. Great. So, now we've covered all the core technology improvements we've made this year. I'd like to now hand it over to Meghna to talk at Core Bluetooth privacy.

结果是你的用户现在可以无缝使用所有多媒体配置文件,无需执行任何操作。以上内容涵盖了我们今年进行的所有核心技术改进。现在我将舞台交给Meghna,她会和大家讨论 Core Bluetooth 隐私方面的变化。

Thank you, Yilok.

谢谢 Yilok。

In the last year alone, there have been an increasing number of instances where applications made the news or we're pulled from the App Store for not respecting user privacy.

仅在去年,就出现了很多应用程序的新闻,由于不尊重用户隐私而被我们从 App Store 下架之类的事件。

I'm here today to help you avoid that situation for your Core Bluetooth applications.

今天我出现在这里,是为了帮助你避免在使用 Core Bluetooth 构建应用程序时出现这类情况。

Hello everyone. My name is Meghna Lav, and over the next few minutes, I'd like to talk you through the privacy update for Core Bluetooth APIs. Privacy matters, and it is more important today than ever before. Our users are more aware of it today than ever before. At Apple, we believe that privacy is a fundamental human right, and as Tim Cook has mentioned, it is our collective responsibility to safeguard and protect the fundamental human right to privacy. As developers in the Apple ecosystem, you all have a profound impact on user's lives every day.

大家好,我是 Meghna Lav。接下来的时间里,我将和大家讨论关于使用 Core Bluetooth 的 APIs 隐私方面的更新。隐私很重要,在今天这个时代越来越重要,今天,我们的用户比以往任何时候都更加了解它。在苹果公司,我们认为隐私是一项基本人权,正如蒂姆·库克(Tim Cook)提到的那样,维护和保护基本隐私权是我们的集体责任【苹果公司的核心价值观里好像有这么一条】。作为Apple生态系统中的开发人员,你们所有人每天都对用户的生活产生深远的影响。

As such, users trust you with their data, and together with us, you shoulder the responsibility to uphold that trust. This year, we've made enhancements to two major areas for Core Bluetooth privacy, user authorization, and accessory notifications. Let's start by talking about user authorization and how it currently works. In iOS 12, if your application instantiated a CBPeripheralManager and wanted to advertise when in the background, we required that you obtain user authorization. New for this year, if your application uses any Core Bluetooth APIs, we'll require you to obtain user authorization.

因此,用户信任你,把他们的数据数据交给你,你应与我们一起承担维护这种信任的责任。今年,关于 Core Bluetooth 的隐私问题,我们在用户授权和附件通知这两个主要领域进行了增强。让我们首先讨论用户授权及其当前的工作方式。在iOS 12中,如果你的应用程序实例化了CBPeripheralManager并想在后台进行广告,则我们需要你获得用户授权。今年的新增功能是,如果你的应用程序使用任何 Core Bluetooth API,我们将要求你获得用户授权。

It is important to note that this applies to applications that are built on older SDKs as well. And when a user makes this decision, they can modify it in the settings app either in the Bluetooth privacy pane or even in your application specific settings. And this is required on iOS, watchOS, and tvOS.

着重要注意的是,这也适用于基于旧版SDK的应用程序。而且,当用户做出此决定时,他们可以在“设置”应用程序中的“蓝牙隐私”窗格里,在你的应用程序特定设置中对其进行修改。这在iOS,watchOS和tvOS上是必需的。

So what does user authorization mean on watchOS. If your application runs as an extension on watchOS, then the permission is shared between iOS and watchOS, and the user only has to grant this permission once. This of course is not true for stand-alone watchOS applications. So, how would you adopt user authorizations in your application? The first thing to do is to open the info.plist of your app and add this new usage description string.

那么用户授权在watchOS上意味着什么。如果你的应用程序在watchOS上作为扩展运行,则该权限在iOS和watchOS之间共享,并且用户只需授予一次此权限, 但对于独立的watchOS应用程序不是这样的。那么,如何在应用程序中采用用户授权呢?首先要做的是打开应用程序的 info.plist 并添加此新的使用情况描述字符串。【NSBluetoothAlwaysUsageDescription

There are three reasons why you should add this usage description string.第60段

这里有三个你应该添加使用情况描述字符串的理由。

First, you can use this to convey to users why your application requires access to Bluetooth. Second it is a mandatory string and failure to adopt it would lead to a crash upon launch for your application. And you see an error like this in console. And thirdly, the app review process reviews all usage description strings to ensure that they are nonempty and meaningful.

首先,你可以使用它向用户传达为什么你的应用程序需要访问蓝牙。其次,它是一个强制性字符串,如果不能采用它,则会在启动应用程序时导致崩溃【这很苹果】,并且你会在控制台中看到相应的错误提示。第三,应用审查流程会审查所有使用情况描述字符串,以确保它们是非空且有意义的。

So let's take a look at some code now. We've created a new property this year that is the authorization property, and this will tell you whether a user has allowed or denied access to your application and whether you check for this authorization property. In order to under that, let's take a look the flow of a Core Bluetooth application. In your Core Bluetooth application, the first thing you probably do is instantiate a CBCentralManager or a CBPeripheralManager.

现在让我们看一些代码【请对照PPT】。今年我们增加了一个 authorization 的属性,它可以告诉你用户授权的状态,是被用户拒绝了,还是你没申请检查。为了解决这个问题,让我们看一下Core Bluetooth应用程序的流程。在Core Bluetooth应用程序中,你可能要做的第一件事是实例化CBCentralManager或CBPeripheralManager。

And so the first delegate callbacks that you will receive from Bluetooth will be the ManagerDidUpdateState callback. In this, you can look at the value of state to see if the manager is ready to be used. Now if the value of state is CBManagerstate.unauthorized, then you can look at a new authorization property to see if the user has denied access to your application. So if your code looks like this today, where you only look at one or two values of manager state, I urge you to please take ten minutes aside today and update your code so it looks a little more like this where you look at all the possible values of manager state, and this also give you a really smooth path to start adopting user authorization in your application. All of this code will be available in the sample project, details of which will be provided in the more info session, section, sorry. Let's now move onto accessory notifications.

然后你可以收到的第一个回调函数是 ManagerDidUpdateState 。在这个回调函数内,你可以检查这个manager的状态是否 ready。现在,如果你检查到是 CBManagerstate.unauthorized 的状态,你可以通过一个这个新的 authorization 属性来判断是不是被用户拒绝了。如果你的代码还是只判断了一两种状态,我希望你改改,你应该判断所有可能的状态,并作出对应的处理。这样子应用在采用用户授权的处理方面会更自然。

Apple implements ANCS, or Apple Notification Center Service, which is a GATT server service that allows your accessories to get system and app notifications from the iOS Notification Center. If you want to learn more about ANCS, then the detailed documentation is available on developer.apple.com. The privacy update for ANCS is that user authorization will now be required in order to share notifications with accessories.

苹果实现了ANCS【Apple Notification Center Service】,这是一项GATT服务器服务,可让你的配件从iOS通知中心获取系统和应用程序通知。如果你想了解有关ANCS的更多信息,那么可以在 developer.apple.com 上找到详细的文档。ANCS的隐私更新是,现在需要用户授权才能与附件共享通知【把配对和通知授权分开了,以前是用户点击配对软件就可以自动完成ANCS授权】。

And so if a user updates to iOS 13, when your accessory connects in and registers for notifications, we'll show this permission prompt to users. Once users make this decision, they can modify it under the device-specific settings in Bluetooth settings.

当用户更新到iOS13之后,外设在连接注册通知服务时,我们会提示用户授权。当用户做出选择之后,他可以在系统设置中指定应用程序授权的页面更改蓝牙设置。

Now, we know that this flow could be a lot better for users if the permission prompt was shown at a time when it was more contextually relevant and in your application.

我们知道,如果权限提示是在上下文相关性更强的时候出现在应用程序中,对于用户来说,这种流程更友好。

And so we've created new ANCS privacy APIs to help you enable this experience.

因此,我们创建了新的ANCS隐私API,以帮助你启用这种体验。

From your CBCentralManager, if you know that the peripheral that you are connecting to supports ANCS, you can use this new CBConnect option. If you do this, then upon successful connection and pairing, we'll show the permission alert to the user while the user is in your application, and when they respond to this permission alert, your application will receive a delegate callback that tells you that ANCS authorization has changed. And you can fetch the value of that using the getter ancsAuthorized. So, we spoke about user authorization and accessory notifications. But apart from this, there's a lot more that your application can do to be a good custodian of user privacy. So let's take a look at some best practices for your Core Bluetooth applications. First and foremost, invoke Core Bluetooth APIs only when required and at a time that it is contextually relevant to users. Next, scan and advertise for a limited duration only.

通过CBCentralManager,如果你知道要连接的外围设备支持ANCS,则可以使用此新的CBConnect选项。如果你这么干了,在成功连接和配对后,当用户在你的应用程序中时,我们将向该用户弹出授权提醒,当用户响应时,你的应用程序将收到委托回调,告诉你 ANCS授权已更改。你可以使用getcs ancsAuthorized获取该值。刚刚我们谈到了用户授权和附件通知。但是除此之外,你的应用程序还可以做很多工作来成为用户隐私的良好监护人。让我们来看一些 Core Bluetooth 应用的最佳实践。第一,仅在需要且与用户上下文相关时才调用 Core Bluetooth APIs。第二,仅在有限的时间内扫描或广播。

When your application is advertising, it is essentially sharing information from the user's phone and limiting the duration for which you do this helps foster user trust.

当你的应用程序在发射广告时,它实际上是在共享用户手机中的信息,限制你的操作持续时间,这有助于增强用户的信任度。

Keep your scan filters as specific as possible and look only for the UUIDs that your application is invested in. And lastly, be transparent with users about why your application requires access to Core Bluetooth. If you do this, then users are more likely to make the right decision. If you want to learn more about designing your applications for privacy, I invite you all to look at the recorded sessions for the privacy talks from this year's and previous years' WWDC sessions.第70段

搜索过滤器尽可能的精确到你想要关注的UUIDS。最后,清晰明确的告诉用户你想用 Core Bluetooth 干些什么。如果你做到了这些,用户一般会同意你的授权提醒的。 如果你想了解有关设计用于隐私的应用程序的更多信息,我邀请大家查看今年和前几年WWDC会议中录制的隐私保护讲座。

So let's all be proactive in thinking about and safeguarding user privacy as we design and implement our Core Bluetooth applications. I'd now like to hand it over to Duy to walk you through developer tools. Thank you.

当我们设计和实施我们的 Core Bluetooth 应用程序时,请让我们所有人积极思考和保护用户隐私。我现在将舞台还给Duy,他将带大家了解开发工具。谢谢。

Thanks. I'd like to talk to you a little bit about a new feature we've added to the Core Bluetooth PacketLogger.

谢谢。我想和大家谈谈我们已添加到 Core Bluetooth PacketLogger 的一项新功能。

For those that's not familiar with the Core Bluetooth PacketLogger, this is our Bluetooth packet analysis application built for Apple developers.

有些朋友可能不太熟悉 Core Bluetooth PacketLogger,这是我们为Apple开发人员构建的Bluetooth数据包分析应用程序。

Today, when you install a login profile on your iOS device and trigger sys diagnose, this is the application that can open up the small PacketLogger file that's inside.

今天,当你在iOS设备上安装登录配置文件并触发sys诊断时,该应用程序可以打开其中的小型PacketLogger文件。

The application can decode all protocols defined by the Bluetooth SIG and by Apple.

该应用程序可以解码Bluetooth SIG和Apple定义的所有协议。

And because it can understand all of these protocols, it will also highlight errors to warn you of potential problems. It has rich filtering options. You can filter by trust connections or protocol. You can search by text or regex, comment and flag individual packets, and even export raw data for later analysis. This is what the top level looks like in dark mode, and in this example, I have filtered only for the ACI and ATT protocols.

并且因为它可以理解所有这些协议,所以它还将突出显示错误以警告你潜在的问题。它具有丰富的过滤选项。你可以按信任连接或协议进行过滤,也可以按文本或正则表达式搜索,注释和标记单个数据包,甚至可以导出原始数据以供以后分析。这就是在暗模式下顶层的外观,在此示例中,我仅过滤了ACI和ATT协议。【请配合PPT查看

But you can also click down, click on each of the packets and drill down to view the full protocol hierarchy and examine each of the protocols individually down to the lowest layer in raw bytes. And new for this year, we've added a feature which we think you're really going to like. It's called Live Capture. This means that you can now install a login profile on your iOS device, connect it to your Mac, launch PacketLogger, and capture live Bluetooth traffic from your iOS device to an accessory. [applause] Thank you. You can also connect multiple iOS devices and capture live traffic.

你也可以单击它,单击每个数据包,然后向下钻取以查看完整的协议层次结构,并分别检查每个协议,直到原始字节中的最低层。在今年的新功能中,我们添加了一个我们认为你确实会喜欢的功能。 它称为实时捕获。 这意味着你现在可以在iOS设备上安装登录配置文件,将其连接到Mac,启动PacketLogger,并捕获从iOS设备到附件的实时蓝牙流量。 []谢谢。 你还可以连接多个iOS设备并捕获实时流量。

We hope that this will give you more context when you debug. It will make your debug more interactive and hopefully help you resolve your problems more quickly.

我们希望这将在调试时为你提供更多上下文。 这将使你的调试更具交互性,并有望帮助你更快地解决问题。

And now that you're excited, how do you set up Live Capture? You can install the iOS 13 developer beta on your iOS device, install the developer logging profile, launch PacketLogger, connect your iOS device to your Mac, select file New iOS Trace on your PacketLogger application, and that's it. You're live capturing.

兴奋了吧,那么如何设置 Live Capture 呢?你可以在iOS设备上安装iOS 13 Beta版本,安装开发人员日志记录配置文件,启动PacketLogger,将iOS设备连接到Mac,然后在PacketLogger应用程序中选择文件New iOS Trace。就可以了。

Thank you. There's also an indicator in your iOS device to tell that Live Capture is in progress. And how do you get PacketLogger? You can download PacketLogger inside the additional tools for Xcode package. The link will be provided in the more information page. PacketLogger is inside the hardware folder of this package.第80段

谢谢。你的iOS设备中还有一个指示器,用于指示Live Capture正在进行中。以及如何获得PacketLogger?你可以在Xcode软件包的其他工具中下载PacketLogger。该链接将在更多信息页面中提供。PacketLogger在此软件包的硬件文件夹中。

For best performance, run with MacOS Catalina. Let's wrap up now with a summary. When developing your accessory use the chipset with the latest Bluetooth stand to take advantage of all of the new performance and power optimizations like LE 2 Mbps and Advertising Extension. You can now build Core Bluetooth apps for Bluetooth BR/EDR devices. We look forward to seeing all of the new applications and accessories you build. And always protect your user privacy and protect their trust in your brand and product. And take advantage of the developer beta. Download the beta and test today.

出于性能问题考虑,请在MacOS Catalina系统版本上运行。现在让我们总结一下。在开发配件时,请使用带有最新蓝牙支架的芯片组来利用所有新的性能和功耗优化,例如LE 2 Mbps和Advertising Extension。你现在可以为Bluetooth BR/EDR设备构建Core Bluetooth应用程序。我们期待看到你构建的新应用程序和外设。并始终保护你的用户隐私,保护他们对你的品牌和产品的信任【苹果还是很白左的嘛】。利用我们发布的 Beta 工具,快去下载 beta 版上手吧。

IOS has very good adoption rates. You don't want your users to run into problems when they upgrade. We usually have a small window to help.

iOS的升级率很高【还不是你们不要脸】。你肯定不希望你的用户升级后还能遇到问题。我们有一个小窗口可以接受意见反馈。

So if you discover a problem early enough, you can work with us to resolve the issues.

所以啊,早点发现你的产品在新系统下的问题所在,我们就能早点解决它。【就是催你升级帮他们找bug呢】

And refer to the accessory design guidelines for Apple devices.

参阅Apple设备的外设设计准则。

We have a great set of guidelines there to tell you how to develop the best accessory.

我们那里有很多指导方针,告诉你如何开发外设的最佳方式。

And finally, Apple is here to help. Use the feedback app, reach out to us so we can work together in your accessories and applications.

最后,苹果在这里为你们提供帮助。使用反馈应用程序,与我们联系,以便我们共同努力解决在你的产品中发现的问题。

And if you have more questions, come to the Core Bluetooth lab at 4.

如果你还有其他问题,请到4号厅 Core Bluetooth 实验室来,我们那有人会帮助你。

Thank you.

谢谢。

你可能感兴趣的:(WWDC2019--Core Bluetooth 新功能)