View in English

  • Apple 开发者
    • 入门汇总

    探索“入门汇总”

    • 概览
    • 学习
    • Apple Developer Program

    及时了解最新动态

    • 最新动态
    • 开发者你好
    • 平台

    探索“平台”

    • Apple 平台
    • iOS
    • iPadOS
    • macOS
    • Apple tvOS
    • visionOS
    • watchOS
    • App Store

    精选

    • 设计
    • 分发
    • 游戏
    • 配件
    • 网页
    • Home
    • CarPlay 车载
    • 技术

    探索“技术”

    • 概览
    • Xcode
    • Swift
    • SwiftUI

    精选

    • 辅助功能
    • App Intents
    • Apple 智能
    • 游戏
    • 机器学习与 AI
    • 安全性
    • Xcode Cloud
    • 社区

    探索“社区”

    • 概览
    • “与 Apple 会面交流”活动
    • 社区主导的活动
    • 开发者论坛
    • 开源

    精选

    • WWDC
    • Swift Student Challenge
    • 开发者故事
    • App Store 大奖
    • Apple 设计大奖
    • Apple Developer Centers
    • 文档

    探索“文档”

    • 文档库
    • 技术概述
    • 示例代码
    • 《人机界面指南》
    • 视频

    发布说明

    • 精选更新
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • Apple tvOS
    • Xcode
    • 下载

    探索“下载”

    • 所有下载
    • 操作系统
    • 应用程序
    • 设计资源

    精选

    • Xcode
    • TestFlight
    • 字体
    • SF Symbols
    • Icon Composer
    • 支持

    探索“支持”

    • 概览
    • 帮助指南
    • 开发者论坛
    • “反馈助理”
    • 联系我们

    精选

    • 《开发者账户帮助》
    • 《App 审核指南》
    • 《App Store Connect 帮助》
    • 即将实行的要求
    • 协议和准则
    • 系统状态
  • 快速链接

    • 活动
    • 新闻
    • 论坛
    • 示例代码
    • 视频
 

视频

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

更多视频

  • 简介
  • 概要
  • 代码
  • 将视觉智能整合到 App 中的最佳做法

    深入了解视觉智能如何改变你 App 中的内容发现体验。探索如何定义实体、处理图像,并高效管理多种结果类型。了解优化速度和相关性的最佳做法,并探索意图如何实现一键打开或播放内容等直接操作。

    章节

    • 0:07 - Introduction
    • 2:02 - Defining your content
    • 5:03 - Implementing a query
    • 8:18 - Opening results
    • 10:03 - Mac and iPad adoption
    • 12:27 - Returning multiple result types
    • 12:56 - Continuing search in your app
    • 14:27 - System store integrations
    • 17:16 - Next steps

    资源

    • Integrating your app with visual intelligence
    • Visual Intelligence
      • 高清视频
      • 标清视频
  • 搜索此视频…
    • 3:21 - Define the content you want to return as an App Entity

      // Define the content you want to return as an App Entity
        import AppIntents
        
        struct AlbumEntity: AppEntity {
            var id: String
            @Property var name: String
            @Property var artistName: String
            var coverArtData: Data
            
            var displayRepresentation: DisplayRepresentation {
                DisplayRepresentation( 
                    title: "\(name)",
                    subtitle: "\(artistName)",
                    image: .init(data: coverArtData)
                )   
            }   
            
            static let defaultQuery = AlbumEntityQuery()
            
            static var typeDisplayRepresentation: TypeDisplayRepresentation { "Album" }
        }   
        
        struct AlbumEntityQuery: EntityQuery {
            @Dependency var catalog: AlbumCatalog
            func entities(for identifiers: [String]) async throws -> [AlbumEntity] {
                catalog.albums(for: identifiers)
            }
        }
    • 5:39 - Adopt IntentValueQuery to return results

      // Adopt IntentValueQuery to return visual search results
        import AppIntents
        import VisualIntelligence
        
        struct SearchHandler: IntentValueQuery {
            @Dependency var catalog: AlbumCatalog
            @Dependency var concertFinder: ConcertFinder
            
            func values(for input: SemanticContentDescriptor) async throws -> [VisualSearchResult] {
                guard let pixelBuffer = input.pixelBuffer else {
                    return []
                }   
                
                let albums = try await catalog.search(matching: pixelBuffer)
                
                return albums.map { VisualSearchResult.album($0) }
            }
        }
      
        --- snippet.
    • 6:24 - Build a catalog of albums with precomputed feature prints

      // Build a catalog of albums with precomputed feature prints
        import Vision
        
        @Observable
        class AlbumCatalog {
            static let shared = AlbumCatalog()
            
            struct CatalogEntry: Sendable {
                let album: AlbumEntity
                let featurePrint: FeaturePrintObservation
            }   
            
            private(set) var entries: [CatalogEntry] = []
            
            private func generateFeaturePrint(
                for image: CGImage
            ) async throws -> FeaturePrintObservation {
                let request = GenerateImageFeaturePrintRequest()
                let result = try await request.perform(on: image)
                return result
            }
        }
    • 6:45 - Search the catalog for albums matching the captured image

      // Search the catalog for albums matching the captured image
        func search(matching pixelBuffer: CVReadOnlyPixelBuffer, limit: Int = 10, maxDistance: Double = 1.0) async throws ->
        [AlbumEntity] {
            var cgImage: CGImage?
            _ = pixelBuffer.withUnsafeBuffer { VTCreateCGImageFromCVPixelBuffer($0, options: nil, imageOut: &cgImage) }
            guard let cgImage else { return [] }
            
            let queryPrint = try await generateFeaturePrint(for: cgImage)
            
            return try entries.compactMap { entry -> (album: AlbumEntity, distance: Double)? in
                let distance = try queryPrint.distance(to: entry.featurePrint)
                guard distance <= maxDistance else { return nil }
                return (entry.album, distance)
            }   
            .sorted { $0.distance < $1.distance }
            .prefix(limit)
            .map { $0.album }
        }   
        
        --
    • 8:27 - Create an open intent to land users on the right screen

      // Create an open intent to land users on the right screen
        import AppIntents
        
        struct OpenAlbumIntent: OpenIntent {
            static let title: LocalizedStringResource = "Open Album"
            
            @Parameter(title: "Album")
            var target: AlbumEntity
            
            @Dependency var appState: AppState
            
            func perform() async throws -> some IntentResult {
                await appState.openAlbum(id: target.id)
                return .result()
            }
        }
    • 12:05 - Use UnionValue to return multiple visual search result types

      // Use UnionValue to return multiple visual search result types
        @UnionValue
        enum VisualSearchResult {
            case album(AlbumEntity)
            case concert(ConcertEntity)
        }   
        
        struct OpenConcertIntent: OpenIntent {
            static let title: LocalizedStringResource = "Open Concert"
            
            @Parameter(title: "Concert")
            var target: ConcertEntity
            
            @Dependency var appState: AppState
            
            func perform() async throws -> some IntentResult {
                await appState.openConcert(id: target.id)
                return .result()
            }
        }
    • 12:18 - Expand the IntentValueQuery to return the UnionValue

      // Expand the IntentValueQuery to return the UnionValue
        struct SearchHandler: IntentValueQuery {
            @Dependency var catalog: AlbumCatalog
            @Dependency var concertFinder: ConcertFinder
            
            func values(for input: SemanticContentDescriptor) async throws -> [VisualSearchResult] {
                guard let pixelBuffer = input.pixelBuffer else {
                    return []
                }   
                
                let albums = try await catalog.search(matching: pixelBuffer)
                
                let artists = albums.map { $0.artistName }
                
                let concerts = await concertFinder.findNearby(byArtists: artists)
      
                return albums.map { VisualSearchResult.album($0) }
                    + concerts.map { VisualSearchResult.concert($0) }
            }
        }
    • 13:13 - Provide a link to in-app search

      // Provide a link to in-app search
        @AppIntent(schema: .visualIntelligence.semanticContentSearch)
        struct SemanticContentSearchIntent: AppIntent {
            static let title: LocalizedStringResource = "Search in app"
            static let openAppWhenRun: Bool = true
            
            var semanticContent: SemanticContentDescriptor
            @Dependency var catalog: AlbumCatalog
            @Dependency var concertFinder: ConcertFinder
            @Dependency var appState: AppState
            
            func perform() async throws -> some IntentResult {
                guard let pixelBuffer = semanticContent.pixelBuffer else { return .result() }
                let albums = try await catalog.search(matching: pixelBuffer)
                let artists = albums.map { $0.artistName }
                let concerts = await concertFinder.findNearby(byArtists: artists)
                await appState.openSearch(albums: albums, concerts: concerts)
                return .result()
            }   
        }
    • 15:24 - Request calendar access and fetch upcoming concerts

      // Request calendar access and fetch upcoming concerts
        import EventKit
        
        @Observable
        class UpcomingConcertManager {
            private let eventStore = EKEventStore()
            var upcomingConcerts: [EKEvent] = []
            var authorizationStatus: EKAuthorizationStatus = .notDetermined
            
            func requestAccessAndFetch() async throws {
                let granted = try await eventStore.requestFullAccessToEvents()
                guard granted else {
                    authorizationStatus = .denied
                    return
                }   
                authorizationStatus = .fullAccess
                await fetchUpcomingConcerts()
      
                // ...
            }
        }
    • 15:42 - Filter for upcoming events that match known artists in our catalog

      // Filter for upcoming events that match known artists in our catalog
        class UpcomingConcertManager {
            func fetchUpcomingConcerts() async {
                let predicate = eventStore.predicateForEvents(
                    withStart: .now,
                    end: .now.addingTimeInterval(90 * 24 * 60 * 60),
                    calendars: nil
                )   
                
                let events = eventStore.events(matching: predicate)
                
                upcomingConcerts = events.filter { event in
                    AlbumCatalog.shared.entries.contains { entry in
                        event.title?.localizedCaseInsensitiveContains(entry.album.artistName) == true
                    }
                }
            }
        }
    • 15:44 - Observe newly created events

      // Observe newly created events
        @Observable
        class UpcomingConcertManager {
            // ...
      
            func requestAccessAndFetch() async throws {
                // ...
      
                for await _ in NotificationCenter.default
                    .notifications(
                        named: .EKEventStoreChanged
                    ) {
                    await fetchUpcomingConcerts()
                }
            }
        }
    • 0:07 - Introduction
    • Visual Intelligence integration and what's new in iOS 26, iPadOS, and macOS, using a sample music-discovery app built throughout the session. Outlines the agenda: defining content, implementing a query, cross-platform adoption, and system store integrations.

    • 2:02 - Defining your content
    • Model your app's content as an AppEntity so Visual Intelligence can display it in search results. Covers the entity's DisplayRepresentation (title, subtitle, thumbnail) and best practices around concise identifying text and thumbnail-sized images.

    • 5:03 - Implementing a query
    • IntentValueQuery returns results from a SemanticContentDescriptor's pixel buffer — using the Vision framework's GenerateImageFeaturePrintRequest for on-device image similarity, with pre-computed feature prints and distance thresholds to keep results fast.

    • 8:18 - Opening results
    • Implement an OpenIntent to take people straight to the selected content. Keep it lightweight since it runs as the app foregrounds, and reuse an existing OpenIntent rather than creating one specific to Visual Intelligence.

    • 10:03 - Mac and iPad adoption
    • The same entities, query, and OpenIntent carry over to iPadOS and macOS with minimal changes. Account for platform differences such as camera versus screenshot input and the much larger pixel buffers on Mac that may need resizing.

    • 12:27 - Returning multiple result types
    • The @UnionValue type returns more than one entity type from a single query — here albums plus nearby concerts — encouraging you to derive related content rather than only matching pixels.

    • 12:56 - Continuing search in your app
    • The semanticContentSearch schema lets people continue into your full in-app search — pre-populating results from the captured context so they land on filters, categories, and deeper content.

    • 14:27 - System store integrations
    • Visual Intelligence can also write data your app reads back via system stores: events through EventKit (EKEventStore), contacts via CNContactStore, and medical-device readings via HealthKit (HKHealthStore). Observe store-change notifications so captured data appears automatically.

    • 17:16 - Next steps
    • Recaps the two integration points, Image Search and system stores, across iOS, iPadOS, and macOS. Points to documentation and related App Intents and Vision sessions.

Developer Footer

  • 视频
  • WWDC26
  • 将视觉智能整合到 App 中的最佳做法
  • 打开菜单 关闭菜单
    • iOS
    • iPadOS
    • macOS
    • Apple tvOS
    • visionOS
    • watchOS
    打开菜单 关闭菜单
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • SF Symbols
    打开菜单 关闭菜单
    • 辅助功能
    • 配件
    • Apple 智能
    • App 扩展
    • App Store
    • 音频与视频 (英文)
    • 增强现实
    • 设计
    • 分发
    • 教育
    • 字体 (英文)
    • 游戏
    • 健康与健身
    • App 内购买项目
    • 本地化
    • 地图与位置
    • 机器学习与 AI
    • 开源资源 (英文)
    • 安全性
    • Safari 浏览器与网页 (英文)
    打开菜单 关闭菜单
    • 完整文档 (英文)
    • 部分主题文档 (简体中文)
    • 教程
    • 下载
    • 论坛 (英文)
    • 视频
    打开菜单 关闭菜单
    • 支持文档
    • 联系我们
    • 错误报告
    • 系统状态 (英文)
    打开菜单 关闭菜单
    • Apple 开发者
    • App Store Connect
    • 证书、标识符和描述文件 (英文)
    • 反馈助理
    打开菜单 关闭菜单
    • Apple Developer Program
    • Apple Developer Enterprise Program
    • App Store Small Business Program
    • MFi Program (英文)
    • Mini Apps Partner 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。
    版权所有 © 2026 Apple Inc. 保留所有权利。
    使用条款 隐私政策 协议和准则