View in English

  • Apple Developer
    • Get Started

    Explore Get Started

    • Overview
    • Learn
    • Apple Developer Program

    Stay Updated

    • Latest News
    • Hello Developer
    • Platforms

    Explore Platforms

    • Apple Platforms
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store

    Featured

    • Design
    • Distribution
    • Games
    • Accessories
    • Web
    • Home
    • CarPlay
    • Technologies

    Explore Technologies

    • Overview
    • Xcode
    • Swift
    • SwiftUI

    Featured

    • Accessibility
    • App Intents
    • Apple Intelligence
    • Games
    • Machine Learning & AI
    • Security
    • Xcode Cloud
    • Community

    Explore Community

    • Overview
    • Meet with Apple events
    • Community-driven events
    • Developer Forums
    • Open Source

    Featured

    • WWDC
    • Swift Student Challenge
    • Developer Stories
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Centers
    • Documentation

    Explore Documentation

    • Documentation Library
    • Technology Overviews
    • Sample Code
    • Human Interface Guidelines
    • Videos

    Release Notes

    • Featured Updates
    • iOS
    • iPadOS
    • macOS
    • watchOS
    • visionOS
    • tvOS
    • Xcode
    • Downloads

    Explore Downloads

    • All Downloads
    • Operating Systems
    • Applications
    • Design Resources

    Featured

    • Xcode
    • TestFlight
    • Fonts
    • SF Symbols
    • Icon Composer
    • Support

    Explore Support

    • Overview
    • Help Guides
    • Developer Forums
    • Feedback Assistant
    • Contact Us

    Featured

    • Account Help
    • App Review Guidelines
    • App Store Connect Help
    • Upcoming Requirements
    • Agreements and Guidelines
    • System Status
  • Quick Links

    • Events
    • News
    • Forums
    • Sample Code
    • Videos
 

Vídeos

Abrir menu Fechar menu
  • Coleções
  • Todos os vídeos
  • Sobre

Mais vídeos

  • Sobre
  • Código
  • What’s new in StoreKit 2 and StoreKit Testing in Xcode

    Get to know the latest enhancements to StoreKit 2 and StoreKit Testing in Xcode. Discover API updates for promoted in-app purchases, StoreKit messages, the Transaction model, the RenewalInfo model, and the App Store sheet for managing subscriptions. Learn how to upgrade to SHA-256 for on-device receipt validation and use APIs to create SwiftUI views.

    We'll also help you get started with StoreKit Testing in Xcode so that you can debug and test your in-app purchases and subscriptions. Meet the Transaction Inspector, explore the latest updates to the StoreKit configuration editor, and find out how you can simulate StoreKit errors to test your app's error handling.

    Recursos

    • Testing failing subscription renewals and In-App Purchases
    • Message
    • Supporting promoted In-App Purchases in your app
    • Turn on Family Sharing for in-app purchases in App Store Connect
    • Setting up StoreKit Testing in Xcode
    • Submit feedback
    • StoreKit
      • Vídeo HD
      • Vídeo SD

    Vídeos relacionados

    WWDC23

    • Explore testing in-app purchases
    • Meet StoreKit for SwiftUI
    • What’s new in App Store Connect

    WWDC22

    • What's new in StoreKit testing
    • What's new with in-app purchase

    WWDC21

    • Meet StoreKit 2
  • Buscar neste vídeo...
    • 1:42 - Create a listener for promoted in-app purchases

      // Create a listener for promoted in-app purchases
      import StoreKit
      
      let promotedPurchasesListener = Task {
          for await promotion in PurchaseIntent.intents {
              // Process promotion
              let product = promotion.product
      
              // Purchase promoted product
              do {
                  let result = try await product.purchase()
                  // Process result
              }
              catch {
                  // Handle error
              }
          }
      }
    • 2:57 - Check promotion order

      // Check promotion order
      import StoreKit
      
      do {
          let promotions = try await Product.PromotionInfo.currentOrder
      
          if promotions.isEmpty {
              // No local promotion order set
          }
      
          for promotion in promotions {
              let productID = promotion.productID
              let productVisibility = promotion.visibility
              // Check promoted products
          }
      }
      catch {
          // Handle error
      }
    • 3:26 - Set a promotion order

      // Set a promotion order
      import StoreKit
      
      let newPromotionOrder: [String] = [
          "acorns.individual",
          "nectar.cup",
          "sunflowerseeds.pile"
      ]
      
      do {
          try await Product.PromotionInfo.updateProductOrder(byID: newPromotionOrder)
      }
      catch {
          // Handle error
      }
    • 4:02 - Update promotion visibility

      // Update promotion visibility
      import StoreKit
      
      // Hide “acorns.individual”
      do {
          try await Product.PromotionInfo.updateProductVisibility(.hidden, for: "acorns.individual")
      }
      catch {
          // Handle error
      }
    • 4:17 - Update promotion visibility (alternative method)

      // Update promotion visibility
      import StoreKit
      
      do {
        let promotions = try await Product.PromotionInfo.currentOrder
      
        // Hide the first product
        if var firstPromotion = promotions.first {
          firstPromotion.visibility = .hidden
          try await firstPromotion.update()
        }
      }
      catch {
        // Handle error
      }
    • 8:32 - Product view

      // Product view
      import SwiftUI
      import StoreKit
      
      struct BirdFoodShop: View {
          let productID: String
          let productImage: String
      
          var body: some View {
              ProductView(id: productID) {
                  BirdFoodProductIcon(for: productID)
              }
              .productViewStyle(.large)
          }
      }
    • 8:52 - Store view

      // Store view
      import SwiftUI
      import StoreKit
      
      struct BirdFoodShop: View {
          let productIDs: [String]
      
          var body: some View {
              StoreView(ids: productIDs) { product in
                  BirdFoodIcon(productID: product.id)
              }
          }
      }
    • 9:19 - Subscription view

      // Subscription view
      import SwiftUI
      import StoreKit
      
      struct BackyardBirdsPassShop: View {
          let groupID: String
      
          var body: some View {
              SubscriptionStoreView(groupID: groupID)
          }
      }
    • 21:09 - Simulated off-device purchase using StoreKitTest

      // Simulated off-device purchase using StoreKitTest
      import StoreKit
      import StoreKitTest
      
      func testSubscriptionRenewal() async throws {
          let session = try SKTestSession(configurationFileNamed: "Store")
      
          let oneYearInterval: TimeInterval = (365 * 24 * 60 * 60)
          let transaction = try await session.buyProduct(
              identifier: "birdpass.individual",
              options: [
                  .purchaseDate(Date.now - oneYearInterval)
              ]
          )
      
          // Inspect transaction
      }
    • 21:48 - Set a simulated purchase error when loading products

      // Set a simulated purchase error when loading products
      import StoreKit
      import StoreKitTest
      
      func testLoadProducts() async throws {
          let session = try SKTestSession(configurationFileNamed: "Store")
          let productIDs = [
              "acorns.individual",
              "nectar.cup"
          ]
      
          // Set a simulated error, then load products, expecting an error
          session.setSimulatedError(.generic(.networkError), forAPI: .loadProducts)
          do {
              _ = try await Product.products(for: productIDs)
              XCTFail("Expected a network error")
          }
          catch StoreKitError.networkError(_) {
              // Expected error thrown, continue...
          }
          // Disable simulated error
          session.setSimulatedError(nil, forAPI: .loadProducts)
      }
    • 22:24 - Set a faster subscription renewal rate in a test session

      // Set a faster subscription renewal rate in a test session
      import StoreKit
      import StoreKitTest
      
      func testSubscriptionRenewal() async throws {
          let session = try SKTestSession(configurationFileNamed: "Store")
      
          // Set renewals to expire every minute
          session.timeRate = .oneRenewalEveryMinute
      
          let transaction = try await session.buyProduct(identifier: "birdpass.individual")
      
          // Wait for renewals and inspect transactions
      }

Developer Footer

  • Vídeos
  • WWDC23
  • What’s new in StoreKit 2 and StoreKit Testing in Xcode
  • Open Menu Close Menu
    • iOS
    • iPadOS
    • macOS
    • tvOS
    • visionOS
    • watchOS
    • App Store
    Open Menu Close Menu
    • Swift
    • SwiftUI
    • Swift Playground
    • TestFlight
    • Xcode
    • Xcode Cloud
    • Icon Composer
    • SF Symbols
    Open Menu Close Menu
    • Accessibility
    • Accessories
    • Apple Intelligence
    • Audio & Video
    • Augmented Reality
    • Business
    • Design
    • Distribution
    • Education
    • Games
    • Health & Fitness
    • In-App Purchase
    • Localization
    • Maps & Location
    • Machine Learning & AI
    • Security
    • Safari & Web
    Open Menu Close Menu
    • Documentation
    • Downloads
    • Sample Code
    • Videos
    Open Menu Close Menu
    • Help Guides & Articles
    • Contact Us
    • Forums
    • Feedback & Bug Reporting
    • System Status
    Open Menu Close Menu
    • Apple Developer
    • App Store Connect
    • Certificates, IDs, & Profiles
    • Feedback Assistant
    Open Menu Close Menu
    • 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 Bounty Program
    • Security Research Device Program
    Open Menu Close Menu
    • Meet with Apple
    • Apple Developer Centers
    • App Store Awards
    • Apple Design Awards
    • Apple Developer Academies
    • WWDC
    Read the latest news.
    Get the Apple Developer app.
    Copyright © 2026 Apple Inc. All rights reserved.
    Terms of Use Privacy Policy Agreements and Guidelines