Hello,
I noticed the Product.SubscriptionInfo subscriptionPeriod (of type Product.SubscriptionPeriod) is different for the same product between StoreKit Testing in Xcode and the sandbox/App Store (production) environment.
For a “1 week” auto-renewable subscription, we get the following:
StoreKit Testing in Xcode: 1 week gives a subscriptionPeriod with value of 1 and a unit of Product.SubscriptionPeriod.Unit.week
Sandbox/App Store: 1 week gives a subscriptionPeriod with value of 7 and a unit of Product.SubscriptionPeriod.Unit.day
This created issues in my app because I used the localizedDescription of a Product.SubscriptionPeriod to display a text similar to “$4.99 per week”. This is what I obtain with the StoreKit Testing in Xcode, but in the Sandbox/App Store environment, it displays “$4.99 per day” (because the subscriptionPeriod is “7 Days” and the unit is then .day). Obviously, this is not what I wanted to display.
Other periods like “1 month”, “2 months”, “3 months”, “6 months, and “1 year”, the period provided by both StoreKit Testing and Sandbox/App Store correspond to the period unit specified in App Store Connect.
In addition, I want to report that for a weekly subscription/offer or a 2 weeks offer, Product.SubscriptionInfo.subscriptionPeriod or Product.SubscriptionOffer.period == .weekly or .everyTwoWeeks is always false.
We observe the following:
With Sandbox or App Store live production:
1 week, Product.SubscriptionInfo.subscriptionPeriod == .weekly is false (because it’s “7 days”)
1 week, Product.SubscriptionOffer.period == .weekly is false (because it’s “7 days”)
2 weeks (offer), Product.SubscriptionInfo.subscriptionPeriod == .everyTwoWeeks is false (because it’s “14 days”)
2 weeks (offer), Product.SubscriptionOffer.period == .everyTwoWeeks is false (because it’s “14 days”)
But with an Xcode StoreKit configuration file:
1 week, Product.SubscriptionInfo.subscriptionPeriod == .weekly is true (because it’s “1 week”)
1 week, Product.SubscriptionOffer.period == .weekly is true (because it’s “1 week”)
2 weeks, Product.SubscriptionInfo.subscriptionPeriod == . everyTwoWeeks is true (because it’s “2 weeks”)
2 weeks, Product.SubscriptionOffer.period == . everyTwoWeeks is true (because it’s “2 weeks”)
So in sandbox and production, .weekly and .everyTwoWeeks is never possible.
If someone from Apple could check the feedback FB19605865 🙂
Thank you
Regards,
Axel, @alpennec
Code:
do {
let productIDs: [String] = ["revenueSocks_weekly_trial"]
let products: [StoreKit.Product] = try await Product.products (for: productIDs)
let weeklySubscription: StoreKit.Product = products.first!
let displayPrice: String = weeklySubscription.displayPrice
// For a weekly subscription in App Store Connect
// With an Xcode StoreKit configuration file: subscriptionPeriod unit is Week (week), value is 1 → "1 Week"
// With the Sandbox + App Store: subscriptionPeriod unit is Day (.day), value is 7 → "7 Days"
let unitString: String = weeklySubscription.subscription!.subscriptionPeriod.unit.localizedDescription
print("\(displayPrice) per \(unitString.localizedLowercase)")
// StoreKit configuration file → "$4.99 per week"
// Sandbox + App Store → "$4.99 per day"
} catch {
print(error)
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Created
Hello,
I'm trying to remove a localization from a String Catalog in a Swift Package. How can I do that?
I tried to remove the file and create a new one, but all the languages are back. The only place where I've found a reference to the languages is in Package/.swiftpm/xcode/package.xcworkspace/xcuserdata/user.xcuserdatad/UserInterfaceState.xcuserstate
But I don't know how to edit this file to remove a language.
Thank you,
Axel
Hello,
I'm planning to had an onboarding to one of my apps. I am thinking about a way for a user to not see the onboarding again if he installs the app on another device. So for example, the user completes the onboarding on its iPhone, then downloads the app on its iPad and launch it, he doesn't see the onboarding a second time.
I thought about using iCloud NSUbiquitousKeyValueStored to store the onboarding completion state.
But I'm not sure when the data is synced to the other device logged into the same Apple account:
Immediately even if the app is not installed on the other device (independent from the app, only iCloud thing)?
At the same time as the app install on the other device?
After the app is first launched on the other device?
Of course synchronisation will depend on the Internet connection, speed, etc. so the app should handle the case where the data is not here but what would be the best case scenario?
Thank you,
Axel
Topic:
App & System Services
SubTopic:
iCloud & Data
Hello,
I'm working on an application that requires the use of significant location changes and visits, in addition to region monitoring and standard continuous location delivery (foreground and background).
iOS 17 and iOS 18 introduced changes to how we can monitor distinct regions of interest (with CLMonitor) as well as receive location updates (with CLLocationUpdate).
But I couldn't find any information regarding how to work with
Significant location changes. Do we still need to create a location manager and call startMonitoringSignificantLocationChanges()? Where are the updates received in this case, in the locationManager(_:didUpdateLocations:) or in the liveUpdates async sequence?
Visits. Same question here, for visit monitoring to work, do we still have to create a location manager then call startMonitoringVisits()? Where are the visits being notified? Still in locationManager(_:didVisit:) or in the liveUpdates asynchronous sequence?
I just want to be sure I understand correctly how to use the updates, and if some features of Core Location still need to use a location manager and the delegate to receive the events.
Maybe additional CLCondition will be added to cover both of these technologies as it seems highly related to monitoring conditions (significant location change, and visit).
Thank you,
Axel
Hello,
I’m presenting the familyActivityPicker from a presented sheet in my application.
When I select some apps, categories or websites and tap “Done”, the familyActivityPicker is dismissed but the presenting sheet is also dismissed on iOS 18.4, iOS 18.5, iOS 26 beta 1 and 2. If I tap on “Cancel” from the familyActivityPicker, the sheet is also dismissed on iOS 18.4, iOS 18.5, iOS 26 beta 1 and 2.
The same code works perfectly fine on iOS 18.0, iOS 18.1, iOS 18.2 and iOS 18.3.
Is this a known-issue?
If opened the feedback FB18369821 for this.
Regards,
Axel
Topic:
App & System Services
SubTopic:
General
Tags:
SwiftUI
Family Controls
Managed Settings
Screen Time
Hello,
When archiving a binary with Xcode, I've always kept my archives in the Organizer so I can symbolicate crash logs using the dSYM files.
I've been thinking about moving to Xcode Cloud for archiving.
Will crash logs still be symbolicated and readable in the Xcode Organizer?
Thank you,
Axel
Hello,
I've noticed the prices of my products in my Xcode synced StoreKit configuration are not updated when I change the price in App Store Connect. I tried to manually sync the file, to remove and add it again to my project but old initial prices are still used.
In the screenshot below, the price is currently $2.99 but the file still uses the initial price of $1.99. It makes testing a little bit painful because I'm never sure which product is being shown.
Is this a bug?
Is there a way to get the live production App Store prices be used instead of the starting prices?
I filed a feedback for this: FB17798486
Regards,
Axel
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags:
StoreKit Test
StoreKit
App Store Connect
Xcode
Hello,
I want to update the prices in all territories of an auto-renewable subscription at once (in a single request). I know it's possible to do it territory by territory using the Create a Subscription Price Change API endpoint, but this means I need to call this API for every territory. And I have a lot of subscriptions I need to update.
There is an another API endpoint that seems to allow to Modify an Auto-Renewable Subscription.
For the countries where I want to change the price, I fetch the subscription price points using the List All Price Points for a Subscription API endpoint.
When I call this API endpoint with the following body (that is the expected body content for this endpoint):
{
"data": {
"type": "subscriptions",
"relationships": {
"prices": {
"data": [
{
"id": "eyJzIjoiNjc0MDAyMTQ5NiIsInQiOiJDQU4iLCJwIjoiMTAwMDEifQ",
"type": "subscriptionPrices"
},
{
"type": "subscriptionPrices",
"id": "eyJzIjoiNjc0MDAyMTQ5NiIsInQiOiJVU0EiLCJwIjoiMTAwMDEifQ"
}
]
}
},
"id": "6740021496"
},
"included": [
{
"relationships": {
"subscriptionPricePoint": {
"data": {
"id": "eyJzIjoiNjc0MDAyMTQ5NiIsInQiOiJDQU4iLCJwIjoiMTAwMDEifQ",
"type": "subscriptionPricePoints"
}
},
"territory": {
"data": {
"type": "territories",
"id": "CAN"
}
},
"subscription": {
"data": {
"id": "6740021496",
"type": "subscriptions"
}
}
},
"id": "eyJzIjoiNjc0MDAyMTQ5NiIsInQiOiJDQU4iLCJwIjoiMTAwMDEifQ",
"attributes": {
"preserveCurrentPrice": true
},
"type": "subscriptionPrices"
},
{
"attributes": {
"preserveCurrentPrice": true
},
"id": "eyJzIjoiNjc0MDAyMTQ5NiIsInQiOiJVU0EiLCJwIjoiMTAwMDEifQ",
"type": "subscriptionPrices",
"relationships": {
"subscription": {
"data": {
"type": "subscriptions",
"id": "6740021496"
}
},
"subscriptionPricePoint": {
"data": {
"type": "subscriptionPricePoints",
"id": "eyJzIjoiNjc0MDAyMTQ5NiIsInQiOiJVU0EiLCJwIjoiMTAwMDEifQ"
}
},
"territory": {
"data": {
"type": "territories",
"id": "USA"
}
}
}
}
]
}
I receive a 409 error:
{
"errors" : [ {
"id" : "5b6a4b62-686c-4a65-87ba-e16131db517b",
"status" : "409",
"code" : "ENTITY_ERROR",
"title" : "There is a problem with the request entity",
"detail" : "User is not allowed to edit.",
"source" : {
"pointer" : "subscriptionPrices"
}
} ]
}
I made sure
my bearer authorisation token is correct and still valid (not expired).
the p8 key has Admin rights
Can this PATCH endpoint be used for what I want to do? If yes, is there anything special to do to use this PATCH endpoint?
Thanks,
Axel
Topic:
App Store Distribution & Marketing
SubTopic:
App Store Connect API
Tags:
App Store
App Store Connect
App Store Connect API
Hello,
I'm trying to create a subscription for one of my apps.
When I specify the Product ID yearly_3, I get the following error message: The Product ID you entered is already being used by another subscription.
This app does not have any other subscriptions with this Product ID.
But I have another app with a yearly_3 Product ID.
According to the official documentation, the Product ID is A unique ID specific to your app. So I thought it was possible to have the same Product ID between apps, but not for the same app.
What's the rule here?
Thanks,
Axel
Topic:
App Store Distribution & Marketing
SubTopic:
App Store Connect
Tags:
Subscriptions
App Store Connect
In-App Purchase
Hello,
I'm currently migrating my app location service to use the new CLLocationUpdate.Updates.
I'm trying to understand what can fail in this AsyncSequence. Based on the previous CLError, I thought authorisation was one of them for example but it turns out that this is handled by the CLLocationUpdate where we can check different properties.
So, is there a list of errors available somewhere?
Thanks
Axel, @alpennec
Hello,
In my app, I have an onboarding made of multiple steps in a NavigationStack.
I also have a state variable that controls an if else root branch to show either the onboarding NavigationStack or the app content if the onboarding is finished.
I noticed that when I end the onboarding (i.e. I switch to the other part of the if else root branch), the onAppear of the first View in the NavigationStack of the onboarding is called again. I don’t understand why.
Is this a bug?
Thanks,
Axel
enum Step {
case one
case two
case three
case four
}
struct ContentView: View {
@State private var isFinished: Bool = false
@State private var steps: [Step] = []
var body: some View {
if isFinished {
Button("Restart") {
steps = []
isFinished = false
}
} else {
NavigationStack(path: $steps) {
VStack {
Text("Start")
.onAppear { print("onAppear: start") }
Button("Go to step 1") { steps.append(.one) }
}
.navigationDestination(for: Step.self) { step in
switch step {
case .one:
Button("Go to step 2") { steps.append(.two) }
.onAppear { print("onAppear: step 1") }
case .two:
Button("Go to step 3") { steps.append(.three) }
.onAppear { print("onAppear: step 2") }
case .three:
Button("Go to step 4") { steps.append(.four) }
.onAppear { print("onAppear: step 3") }
case .four:
Button("End") {
isFinished = true
}
.onAppear { print("onAppear: end") }
}
}
}
.onAppear { print("onAppear: NavigationStack") }
}
}
}
Hello,
SwiftData is not working correctly with Swift Concurrency. And it’s sad after all this time.
I personally found a regression. The attached code works perfectly fine on iOS 17.5 but doesn’t work correctly on iOS 18 or iOS 18.1.
A model can be updated from the background (Task, Task.detached or ModelActor) and refreshes the UI, but as soon as the same item is updated from the View (fetched via a Query), the next background updates are not reflected anymore in the UI, the UI is not refreshed, the updates are not merged into the main.
How to reproduce:
Launch the app
Tap the plus button in the navigation bar to create a new item
Tap on the “Update from Task”, “Update from Detached Task”, “Update from ModelActor” many times
Notice the time is updated
Tap on the “Update from View” (once or many times)
Notice the time is updated
Tap again on “Update from Task”, “Update from Detached Task”, “Update from ModelActor” many times
Notice that the time is not update anymore
Am I doing something wrong? Or is this a bug in iOS 18/18.1?
Many other posts talk about issues where updates from background thread are not merged into the main thread. I don’t know if they all are related but it would be nice to have
1/ bug fixed, meaning that if I update an item from a background, it’s reflected in the UI, and
2/ proper documentation on how to use SwiftData with Swift Concurrency (ModelActor). I don’t know if what I’m doing in my buttons is correct or not.
Thanks,
Axel
import SwiftData
import SwiftUI
@main
struct FB_SwiftData_BackgroundApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.modelContainer(for: Item.self)
}
}
}
struct ContentView: View {
@Environment(\.modelContext) private var modelContext
@State private var simpleModelActor: SimpleModelActor!
@Query private var items: [Item]
var body: some View {
NavigationView {
VStack {
if let firstItem: Item = items.first {
Text(firstItem.timestamp, format: Date.FormatStyle(date: .omitted, time: .standard))
.font(.largeTitle)
.fontWeight(.heavy)
Button("Update from Task") {
let modelContainer: ModelContainer = modelContext.container
let itemID: Item.ID = firstItem.persistentModelID
Task {
let context: ModelContext = ModelContext(modelContainer)
guard let itemInContext: Item = context.model(for: itemID) as? Item else { return }
itemInContext.timestamp = Date.now.addingTimeInterval(.random(in: 0...2000))
try context.save()
}
}
.buttonStyle(.bordered)
Button("Update from Detached Task") {
let container: ModelContainer = modelContext.container
let itemID: Item.ID = firstItem.persistentModelID
Task.detached {
let context: ModelContext = ModelContext(container)
guard let itemInContext: Item = context.model(for: itemID) as? Item else { return }
itemInContext.timestamp = Date.now.addingTimeInterval(.random(in: 0...2000))
try context.save()
}
}
.buttonStyle(.bordered)
Button("Update from ModelActor") {
let container: ModelContainer = modelContext.container
let persistentModelID: Item.ID = firstItem.persistentModelID
Task.detached {
let actor: SimpleModelActor = SimpleModelActor(modelContainer: container)
await actor.updateItem(identifier: persistentModelID)
}
}
.buttonStyle(.bordered)
Button("Update from ModelActor in State") {
let container: ModelContainer = modelContext.container
let persistentModelID: Item.ID = firstItem.persistentModelID
Task.detached {
let actor: SimpleModelActor = SimpleModelActor(modelContainer: container)
await MainActor.run {
simpleModelActor = actor
}
await actor.updateItem(identifier: persistentModelID)
}
}
.buttonStyle(.bordered)
Divider()
.padding(.vertical)
Button("Update from View") {
firstItem.timestamp = Date.now.addingTimeInterval(.random(in: 0...2000))
}
.buttonStyle(.bordered)
} else {
ContentUnavailableView(
"No Data",
systemImage: "slash.circle", //
description: Text("Tap the plus button in the toolbar")
)
}
}
.toolbar {
ToolbarItem(placement: .primaryAction) {
Button(action: addItem) {
Label("Add Item", systemImage: "plus")
}
}
}
}
}
private func addItem() {
modelContext.insert(Item(timestamp: Date.now))
try? modelContext.save()
}
}
@ModelActor
final actor SimpleModelActor {
var context: String = ""
func updateItem(identifier: Item.ID) {
guard let item = self[identifier, as: Item.self] else {
return
}
item.timestamp = Date.now.addingTimeInterval(.random(in: 0...2000))
try! modelContext.save()
}
}
@Model
final class Item: Identifiable {
var timestamp: Date
init(timestamp: Date) {
self.timestamp = timestamp
}
}
Hello,
I'm trying to understand how dangerous it is to read and/or update model properties from a thread different than the one that instantiated the model.
I know this is wrong when using Core Data and we should always use perform/performAndWait before manipulating an object but I haven't found any information about that for SwiftData.
Question: is it safe to pass an object from one thread (like MainActor) to another thread (in a detached Task for example) and manipulate it, or should we re fetch the object using its persistentModelID as soon as we cross threads?
When running the example app below with the -com.apple.CoreData.ConcurrencyDebug 1 argument passed at launch enabled, I don't get any Console warning when I tap on the "Update directly" button. I'm sure it would trigger a warning if I were using Core Data.
Thanks in advance for explaining.
Axel
--
@main
struct SwiftDataPlaygroundApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.modelContainer(for: Item.self)
}
}
}
struct ContentView: View {
@Environment(\.modelContext) private var context
@Query private var items: [Item]
var body: some View {
VStack {
Button("Add") {
context.insert(Item(timestamp: Date.now))
}
if let firstItem = items.first {
Button("Update directly") {
Task.detached {
// Not the main thread, but firstItem is from the main thread
// No warning in Xcode
firstItem.timestamp = Date.now
}
}
Button("Update using persistentModelID") {
let container: ModelContainer = context.container
let itemIdentifier: Item.ID = firstItem.persistentModelID
Task.detached {
let backgroundContext: ModelContext = ModelContext(container)
guard let itemInBackgroundThread: Item = backgroundContext.model(for: itemIdentifier) as? Item else { return }
// Item on a background thread
itemInBackgroundThread.timestamp = Date.now
try? backgroundContext.save()
}
}
}
}
}
}
@Model
final class Item: Identifiable {
var timestamp: Date
init(timestamp: Date) {
self.timestamp = timestamp
}
}
Hello,
I'm currently developing an app using SwiftData.
I want the app to use CloudKit to sync data, so I made sure all my model properties are optional.
I've defined a Codable enum as follows:
enum Size: Int, Codable {
case small
case medium
case large
}
I've defined a Drink SwiftData model as follows:
@Model
class Drink {
var name: String?
var size: Size?
init(
name: String? = nil,
size: Size? = nil
) {
self.name = name
self.size = size
}
}
In one of my Views, I want to use a @Query to fetch the data, and use a Predicate to filter the data. The Predicate uses the size enumeration of the Drink model. Here is the code:
struct DrinksView: View {
@Query var drinks: [Drink]
init() {
let smallRawValue: Int = Size.small.rawValue
let filter: Predicate<Drink> = #Predicate<Drink> { drink in
if let size: Size = drink.size {
return size.rawValue == smallRawValue
} else {
return false
}
}
_drinks = Query(filter: filter)
}
var body: some View {
List {
ForEach(drinks) { drink in
Text(drink.name ?? "Unknown Drink")
}
}
}
}
The code compiles, but when I run the app, it crashes with the following error:
Thread 1: Fatal error: Couldn't find \Drink.size!.rawValue on Drink with fields [SwiftData.Schema.PropertyMetadata(name: "name", keypath: \Drink.name, defaultValue: nil, metadata: nil), SwiftData.Schema.PropertyMetadata(name: "size", keypath: \Drink.size, defaultValue: nil, metadata: nil)]
How can I filter my data using this optional variable on the Drink model?
Thanks,
Axel
Hello,
I'm trying to clear the purchase history made with a sandbox Apple ID on my test device but it does not work. The past purchases are still returned by StoreKit. I've waited many hours but it seems to persist.
When I use for await result in Transaction.currentEntitlements { in my app, my non-consumable product is still here.
Is it expected?
How long should it take to reset the history?
Is is supposed to work also for non-consumable products?
Thanks
Axel
Topic:
App & System Services
SubTopic:
StoreKit
Tags:
App Store Connect
Subscriptions
In-App Purchase
StoreKit