Hi,
I'd like to call an Async function upon a state change or onAppear() but I'm not sure how to do so. Below is my code:
.onAppear() {
if !subscribed {
await Subscriptions().checkSubscriptionStatus()
}
}
class Subscriptions {
var subscribed = UserDefaults.standard.bool(forKey: "subscribed")
func checkSubscriptionStatus() async {
if !subscribed {
await loadProducts()
}
}
func loadProducts() async {
for await purchaseIntent in PurchaseIntent.intents {
// Complete the purchase workflow.
await purchaseProduct(purchaseIntent.product)
}
}
func purchaseProduct(_ product: Product) async {
// Complete the purchase workflow.
do {
try await product.purchase()
}
catch {
// Add your error handling here.
}
// Add your remaining purchase workflow here.
}
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I was wondering if errors are common for the code below for saving SwiftData data and what would be the best way to handle them (popup, closing the app)?
do {
try modelContext.save()
} catch {
print("error")
}
I was wondering if there was a way to submit an app for review before completing the terms of service and privacy policy in case the app does not get approved.
Hello,
I'm having issues with Safari's inspect element. Some of the elements on a webpage I'm working on aren't showing up, however they are present under the Sources tab. I'm not sure why that is. Any help would be greatly appreciated.
Thank you
Update: I made a coding error, it had nothing to do with web inspector.
Hi,
I have a view that takes an optional binding boolean variable. I'd like to pass a variable to it from certain views only. The problem I'm having is when I pass a variable, I get the error "Cannot convert value of type 'Binding' to expected argument type 'Binding<Bool?>'", and when I don't, I get the error "Missing argument for parameter 'toggle' in call". Below Is the code I have. Thank you.
Heading(text: "Heading1") // error: Missing argument for parameter 'toggle' in call
Heading(text: "Heading2", toggle: $newEntry) // Cannot convert value of type 'Binding<Bool>' to expected argument type 'Binding<Bool?>'
struct Heading: View {
@State var text: String
@Binding var toggle: Bool?
var body: some View {
VStack {
Spacer()
.frame(height: 25)
HStack {
Text(text)
.font(.system(size: 36))
Spacer()
if text == "str" {
Button(action: { toggle!.toggle() }) {
Image(systemName: "plus")
.foregroundColor(.black)
.font(.system(size: 36))
}
}
}
Spacer()
.frame(height: 25)
}
}
}
Hi,
For HTTP requests, I have the following function:
func createAccount(account: Account, completion: @escaping (Response) -> Void) {
guard let url = URL(string: "http://localhost:4300/account") else { return }
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
guard let encoded = try? JSONEncoder().encode(account) else {
print("Failed to encode request")
return
}
request.httpBody = encoded
URLSession.shared.dataTask(with: request) { (data, response, error) in
guard let data = data else { return }
do {
let resData = try JSONDecoder().decode(Response, from: data)
DispatchQueue.main.async {
completion(resData)
}
} catch let jsonError as NSError {
print("JSON decode failed: \(jsonError)")
}
}.resume()
}
Because various HTTP requests use different body structs and response structs, I have a HTTP request function for each individual HTTP request. How can I condense this into one function, where the passed struct and return struct are varying, so I can perhaps pass the struct types in addition to the data to the function? Any guidance would be greatly appreciated.
I updated the price of subscriptions within an app in App Store Connect, however the new price does not show within the test app. I would just like to make sure that if the app is released that the subscription price is set to the most recent price. Is there any way to confirm that and is there a way to see the new price in the test app?
Topic:
App Store Distribution & Marketing
SubTopic:
App Store Connect
Tags:
Subscriptions
StoreKit
App Store Connect