Question

Why does iOS subscription lapse occasionally? ( SwiftUI and WidgetKit )

  • 12 September 2021
  • 0 replies
  • 16 views

Badge

My app has been live on the app store for 20 days, it provides monthly and annual subscription services. About 1% of subscribers report to me that the subscription status has become invalid, they need to restore their subscription status by restoring purchases.

 

I tried to test this problem, but I can't get started. Once, the subscription status in the app on my device was normal, but the subscription status in the widget was invalid. In this case, I could not resume the purchase (because the purchase was made in the non-subscription state in the app), and finally returned to normal by overwriting the installation.

 

So I want to know why the problem occurs, is it because my code is incorrect? 

Please help me, thanks!

 

Code

01 init in the app

init() {
setupRevenueCat()
}

func setupRevenueCat() {

Purchases.configure(withAPIKey: xxxxxx,
appUserID: nil,
observerMode: false,
userDefaults: UserDefaults(suiteName: "group.xxxxxx.xxx"))

}

02 get subscription status in the app

class PurchaseModel: ObservableObject {

@Published var allAccess = false

init() {

Purchases.shared.purchaserInfo { (info, error) in

if info?.entitlements["allaccess"]?.isActive == true {

self.allAccess = true

}
}
}
}
struct ContentView: View {

@EnvironmentObject var model: PurchaseModel

var body: some View {

......

if model.allAccess {...}
}
}

03 get subscription status in the iOS 14+ widget

struct Provider: IntentTimelineProvider {

init(){
setupRevenueCat()
}

......

func getTimeline(for configuration: MyIntentsIntent, in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {

Purchases.shared.purchaserInfo { (info, error) in

if info?.entitlements["allaccess"]?.isActive == true {
......
completion(timeline)
}
}
}

func setupRevenueCat() {

Purchases.configure(withAPIKey: xxxxxx,
appUserID: nil,
observerMode: false,
userDefaults: UserDefaults(suiteName: "group.xxxxxx.xxx"))

}
}

 


0 replies

Be the first to reply!

Reply