Discussions
Request for Code Review and Concern about Qonversion Integration Impact on App Performance
4 months ago by Yan Cheng Cheok
Currently, I have modified three functions to insert Qonversion-related code. Can you help me review whether I have done it correctly?
I have another concern. If, after trying, I am not satisfied with the outcome and decide not to purchase any plan from Qonversion, will the newly added Qonversion-related code affect my app’s performance in production?
Thank you.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
...
let config = Qonversion.Configuration(projectKey: "XXX", launchMode: .analytics)
Qonversion.initWithConfig(config)
return true
}
private func listenForTransactions() -> Task<Void, Error> {
return Task.detached {
//Iterate through any transactions which didn't come from a direct call to `purchase()`.
for await result in Transaction.updates {
do {
let transaction = try self.checkVerified(result)
//Deliver content to the user.
await self.updatePurchasedIdentifiers(transaction)
//https://documentation.qonversion.io/docs/analytics-mode
await QonversionSwift.shared.handleTransaction(transaction)
//Always finish a transaction.
await transaction.finish()
} catch {
//StoreKit has a receipt it can read but it failed verification. Don't deliver content to the user.
error_log(error)
}
}
}
}
func purchase(_ shop: Shop) async -> Bool {
guard let product = products.filter({ $0.id == shop.identifier }).first else { return false }
do {
//Begin a purchase.
let result = try await product.purchase()
switch result {
case .success(let verification):
let transaction = try checkVerified(verification)
//Deliver content to the user.
await updatePurchasedIdentifiers(transaction)
//https://documentation.qonversion.io/docs/analytics-mode
await QonversionSwift.shared.handleTransaction(transaction)
//Always finish a transaction.
await transaction.finish()
return true
case .userCancelled, .pending:
return false
default:
return false
}
} catch {
error_log(error)
}
return false
}