Reputation: 1670
I want to create a button where a user can cancel a auto-renewal subscription (or get redirected to App Store).
Is that possible without the user having to go through the whole purchase process first? If it is, how would you go about doing it?
Upvotes: 34
Views: 19305
Reputation: 708
The correct URL is now https://apps.apple.com/account/subscriptions according to Apple's Handling Subscriptions Billing Documentation.
So just use:
UIApplication.shared.open(URL(string: "https://apps.apple.com/account/subscriptions")!)
Upvotes: 51
Reputation: 531
Since iOS 15.0+, one can use the following API from StoreKit:
if let windowScene = UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene {
Task {
do {
try await AppStore.showManageSubscriptions(in: windowScene)
} catch {
// Handle potential error
}
}
}
This presents a native modal that keeps the user in your app. I would say it provides a more neat experience than doing the old openURL
API.
Upvotes: 0
Reputation: 613
April 2021
According to the Apple Document, the URL has been updated to
https://apps.apple.com/account/subscriptions
So the following code can be used to redirect the user to manage subscriptions page.
DispatchQueue.main.async {
UIApplication.shared.open(URL(string: "https://apps.apple.com/account/subscriptions")!, options: [:], completionHandler: nil)
}
Upvotes: -3
Reputation: 115002
From the Apple In-App Purchase Programming Guide -
Rather than needing to code your own subscription management UI, your app can open the following URL:
https://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/manageSubscriptions Opening this URL launches iTunes or iTunes Store, and then displays the Manage Subscription page.
So, simply create a button that launches that URL.
UIApplication.shared.openURL(URL(string: "https://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/manageSubscriptions")!)
Upvotes: 36
Reputation: 163
iOS 10 and above
UIApplication.shared.open(URL(string: "https://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/manageSubscriptions")!, options: [:], completionHandler: nil)
Upvotes: 0
Reputation: 9361
As mentioned in the documentation: https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Chapters/Subscriptions.html#//apple_ref/doc/uid/TP40008267-CH7-SW19
So for Swift 3/4 just use this
UIApplication.shared.openURL(URL(string: "https://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/manageSubscriptions")!)
Upvotes: 3