Skip to content

Commit

Permalink
Fix notificatins authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanov91 committed Jul 3, 2023
1 parent 9f6f6a2 commit f0ff632
Showing 1 changed file with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,19 +303,21 @@ extension StoreViewModel {

func addTrialNotification(product: Product) async {
if product.type == .autoRenewable, product.subscription?.introductoryOffer != nil {
let result = await localNotificationService.requestAccess()
if case let .success(status) = result, status, let trialDaysCount = product.trialDaysCount {
let timeInterval = TimeInterval((trialDaysCount - 2) * 24 * 60 * 60)
let notificationTime = Date().addingTimeInterval(timeInterval)
let dateComponents = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute], from: notificationTime)
await localNotificationService.schedule(localNotification: .init(
id: UUID(),
title: "Trial ends soon",
body: "Subscription ends in 2 days",
dateComponents: dateComponents,
repeats: false
))
}
do {
try await localNotificationService.requestAuthorization()
if let trialDaysCount = product.trialDaysCount {
let timeInterval = TimeInterval((trialDaysCount - 2) * 24 * 60 * 60)
let notificationTime = Date().addingTimeInterval(timeInterval)
let dateComponents = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute], from: notificationTime)
await localNotificationService.schedule(localNotification: .init(
id: UUID(),
title: "Trial ends soon",
body: "Subscription ends in 2 days",
dateComponents: dateComponents,
repeats: false
))
}
} catch {}
}
}
}
Expand Down

0 comments on commit f0ff632

Please sign in to comment.