View in English

  • 打开菜单 关闭菜单
  • Apple Developer
搜索
关闭搜索
  • Apple Developer
  • 新闻
  • 探索
  • 设计
  • 开发
  • 分发
  • 支持
  • 账户
在“”范围内搜索。

快捷链接

5 快捷链接

视频

打开菜单 关闭菜单
  • 专题
  • 相关主题
  • 所有视频
  • 关于

返回 WWDC20

大多数浏览器和
Developer App 均支持流媒体播放。

  • 简介
  • 转写文稿
  • 代码
  • 核心 NFC 的新功能

    核心 NFC 可以帮助您扫描和写入 app 中的 NFC 标签,帮助人们从停车收费表,踏板车租赁,汽车充电站等物品中获得更多收益。了解核心 NFC 对 ISO15693 协议的支持、新的标签功能,并找出更多的 Swift 语法改进之处。

    资源

    • Creating NFC Tags from Your iPhone
      • 高清视频
      • 标清视频

    相关视频

    WWDC19

    • Core NFC 增强功能
  • 搜索此视频…

    Hello and welcome to WWDC.

    Hi, my name is Lawrence and I work on NFC software here at Apple.

    Today we will go over the changes in our existing APIs. These changes follow some of the new published Swift guidelines.

    We have also expanded our APIs for the ISO15693 tag used in NFCTagReaderSession. First, let's start with an overview of Core NFC. You may recall our creative salmon from our last year WWDC presentation.

    By the way, his name is Kevin.

    Today I have brought Kevin with me and here is the coupon tag.

    Core NFC allows your app to read this NFC tag using an iPhone.

    NFC is also used in other places, such as on parking meters, scooter rental, electric car charging station, ordering menu in restaurant, et cetera. Core NFC allows an app to read an NFC tag in a session lasting up to 60 seconds. This has been supported on iPhones since the iPhone 7. Beginning on the iPhone XS, tags can also be read in the background while the screen is on, if the NFC forum NDEF message contains a universal link. Once the user has tapped on the notification banner shown on screen that NDEF message will be sent to your application as an NSUserActivity via UIApplicationDelegate restorationHandler. Texts may contain a NFC forum NDEF message or other proprietary data set.

    Core NFC supports NDEF reading and writing as well as other native tag protocols.

    The easiest path for tag access is to use the NFCNDEFReaderSession.

    Core NFC supports NDEF reading and writing as well as other native tag protocols.

    The easiest path for tag access is to use the NFCNDEFReaderSession. But Core NFC also supports raw tag communication via ISO7816, FeliCa, MIFARE and ISO15693. Next, let's talk about some changes to the Swift syntax to make it easier to understand your Core NFC code.

    Core NFC now adopts the use of the Result enum in our tag APIs, specifically how parameters are returned in our completion handler. Let's look at the ISO7816-tag-send-command as an example. Before iOS 14, the method signature accepts a closure with four arguments as the completion handler. Your application will need to check the optional error object to determine if an error occurs. If the operation succeeds, you may then parse the rest of arguments to collect the results. The new signature in iOS 14 returns a Result enum of either a NFCISO7816-Response-APDU object on success, which is the result of reading the tag, or an error object on a failure. The Result enum can be easily handled using a switch statement as shown.

    Now let me show you how it looks in Xcode.

    I've opened the NFCFishTag sample project from WWDC 2019. Here, in CouponViewController, the write function is shown in its existing form. Let's replace the send-MIFARE-command using its new Result signature.

    Here, in the new code, the data object is handled in this section of a switch statement. An error is handled over here.

    We have also made a few changes to the existing enum values to improve readability. For example, the ResolveFlag enum has been changed to refer specifically to ISO15693. Some other new enums have been added as well. Please refer to the documentation for more details. Now we will talk about new capabilities we've added to the NFC-ISO15693 tag protocol. We have added the enhancement defined by the ISO15693 specification third edition 2019. These functions are useful for tags with larger memory sizes and security operations. We have also included a new generic send command if you would like to send arbitrary data packets for your application. Here is a complete list of the enhancement function signatures under the NFC-ISO15693Tag protocol.

    We now support the following operations: fast reading multiple blocks, extended write multiple blocks, authenticate, key update, challenge, read buffer, extended get multiple blocks security status, extended fast read multiple blocks and send request.

    That's what new in Core NFC this year. We look forward to seeing what you can make with it.

    • 3:24 - sendCommand

      detectedTag.sendCommand(apdu: apdu) { (result: Result<NFCISO7816ResponseAPDU, Error>) in
         switch result {
         case .success(let responseAPDU):
            /// Handle NFCISO7816ResponseAPDU object.
         case .failure(let error):
            /// Handle Error object.
         }
      }
    • 4:06 - sendMiFareCommand

      // You need to zero-pad the data to fill the block size
      if blockData.count < blockSize {
        blockData += Data(count: blockSize - blockData.count)
      }
      
      let writeCommand = Data([writeBlockCommand, offset]) + blockData
      tag.sendMiFareCommand(commandPacket: writeCommand) { (response: Result<Data, Error>) in
        switch (response) {
        case .success(let responseData):
          if responseData[0] != successCode {
            self.readerSession?.invalidate(errorMessage: "Write tag error. Please try again.")
            return
          }
          
          let newSize = data.count - blockSize
          if newSize > 0 {
            self.write(data.suffix(newSize), to: tag, offset: (offset + 1))
          } else {
            self.readerSession?.invalidate()
          }
        case .failure(let error):
          let message = "Write tag error: \(error.localizedDescription). Please try again."
          self.readerSession?.invalidate(errorMessage: message)
        }
      }

Developer Footer

  • 视频
  • WWDC20
  • 核心 NFC 的新功能
  • 打开菜单 关闭菜单
    • iOS
    • iPadOS
    • macOS
    • Apple tvOS
    • visionOS
    • watchOS
    打开菜单 关闭菜单
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • SF Symbols
    打开菜单 关闭菜单
    • 辅助功能
    • 配件
    • App 扩展
    • App Store
    • 音频与视频 (英文)
    • 增强现实
    • 设计
    • 分发
    • 教育
    • 字体 (英文)
    • 游戏
    • 健康与健身
    • App 内购买项目
    • 本地化
    • 地图与位置
    • 机器学习
    • 开源资源 (英文)
    • 安全性
    • Safari 浏览器与网页 (英文)
    打开菜单 关闭菜单
    • 完整文档 (英文)
    • 部分主题文档 (简体中文)
    • 教程
    • 下载 (英文)
    • 论坛 (英文)
    • 视频
    打开菜单 关闭菜单
    • 支持文档
    • 联系我们
    • 错误报告
    • 系统状态 (英文)
    打开菜单 关闭菜单
    • Apple 开发者
    • App Store Connect
    • 证书、标识符和描述文件 (英文)
    • 反馈助理
    打开菜单 关闭菜单
    • Apple Developer Program
    • Apple Developer Enterprise Program
    • App Store Small Business Program
    • MFi Program (英文)
    • News Partner Program (英文)
    • Video Partner Program (英文)
    • 安全赏金计划 (英文)
    • Security Research Device Program (英文)
    打开菜单 关闭菜单
    • 与 Apple 会面交流
    • Apple Developer Center
    • App Store 大奖 (英文)
    • Apple 设计大奖
    • Apple Developer Academies (英文)
    • WWDC
    获取 Apple Developer App。
    版权所有 © 2025 Apple Inc. 保留所有权利。
    使用条款 隐私政策 协议和准则