使用 Swift 取消自动续订订阅

Cancel auto-renewal subscriptions with Swift

我想创建一个按钮,用户可以在其中取消自动续订订阅(或重定向到 App Store)。

用户不必先完成整个购买过程是否可能?如果是,你会怎么做?

来自 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.

因此,只需创建一个按钮即可启动 URL。

UIApplication.shared.openURL(URL(string: "https://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/manageSubscriptions")!)

如文档中所述: https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Chapters/Subscriptions.html#//apple_ref/doc/uid/TP40008267-CH7-SW19

所以 Swift 3/4 就用这个

UIApplication.shared.openURL(URL(string: "https://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/manageSubscriptions")!)

iOS 10岁及以上

UIApplication.shared.open(URL(string: "https://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/manageSubscriptions")!, options: [:], completionHandler: nil)

2019 年 12 月

现在正确的 URL 是 https://apps.apple.com/account/subscriptions according to Apple's Handling Subscriptions Billing Documentation

所以只需使用:

UIApplication.shared.open(URL(string: "https://apps.apple.com/account/subscriptions")!)

2021 年 4 月

根据Apple Document,URL已更新为

https://apps.apple.com/account/subscriptions

因此可以使用以下代码将用户重定向到管理订阅页面。

DispatchQueue.main.async {
      UIApplication.shared.open(URL(string: "https://apps.apple.com/account/subscriptions")!, options: [:], completionHandler: nil)
    }