WIP: ios push notification permission UX
This commit is contained in:
@ -76,6 +76,26 @@ struct ProfileView: View {
|
||||
#endif
|
||||
}
|
||||
|
||||
private var accountSection: some View {
|
||||
Section {
|
||||
NavigationLink(destination: LabelsView()) {
|
||||
Text("Labels")
|
||||
}
|
||||
|
||||
NavigationLink(destination: NewsletterEmailsView()) {
|
||||
Text("Emails")
|
||||
}
|
||||
|
||||
NavigationLink(destination: SubscriptionsView()) {
|
||||
Text("Subscriptions")
|
||||
}
|
||||
|
||||
NavigationLink(destination: GroupsView()) {
|
||||
Text("Recommendation Groups")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var innerBody: some View {
|
||||
Group {
|
||||
Section {
|
||||
@ -85,26 +105,13 @@ struct ProfileView: View {
|
||||
}
|
||||
}
|
||||
|
||||
Section {
|
||||
NavigationLink(destination: LabelsView()) {
|
||||
Text("Labels")
|
||||
}
|
||||
|
||||
NavigationLink(destination: NewsletterEmailsView()) {
|
||||
Text("Emails")
|
||||
}
|
||||
|
||||
NavigationLink(destination: SubscriptionsView()) {
|
||||
Text("Subscriptions")
|
||||
}
|
||||
|
||||
NavigationLink(destination: GroupsView()) {
|
||||
Text("Recommendation Groups")
|
||||
}
|
||||
}
|
||||
accountSection
|
||||
|
||||
#if os(iOS)
|
||||
Section {
|
||||
NavigationLink(destination: PushNotificationSettingsView()) {
|
||||
Text("Push Notifications")
|
||||
}
|
||||
NavigationLink(destination: TextToSpeechView()) {
|
||||
Text("Text to Speech")
|
||||
}
|
||||
|
||||
@ -0,0 +1,80 @@
|
||||
import Models
|
||||
import Services
|
||||
import SwiftUI
|
||||
import Utils
|
||||
import Views
|
||||
|
||||
@MainActor final class PushNotificationSettingsViewModel: ObservableObject {
|
||||
@Published var isLoading = false
|
||||
@Published var emails = [NewsletterEmail]()
|
||||
@Published var desiredNotificationsEnabled = false
|
||||
@AppStorage(UserDefaultKey.notificationsEnabled.rawValue) var notificationsEnabled = false
|
||||
|
||||
func checkPushNotificationsStatus() {
|
||||
UNUserNotificationCenter.current().getNotificationSettings { settings in
|
||||
DispatchQueue.main.async {
|
||||
self.desiredNotificationsEnabled = settings.alertSetting == UNNotificationSetting.enabled
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func tryUpdateToDesired() {
|
||||
print("trying to update to desired state: ", desiredNotificationsEnabled)
|
||||
if desiredNotificationsEnabled {
|
||||
UNUserNotificationCenter.current().requestAuthorization(options: [.alert]) { granted, error in
|
||||
print("notification status: ", granted, "error: ", error)
|
||||
DispatchQueue.main.async {
|
||||
self.desiredNotificationsEnabled = granted
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// UNUserNotificationCenter.current().r
|
||||
UIApplication.shared.openURL(URL(string:"prefs:root=NOTIFICATIONS_ID")!)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct PushNotificationSettingsView: View {
|
||||
@EnvironmentObject var dataService: DataService
|
||||
@StateObject var viewModel = PushNotificationSettingsViewModel()
|
||||
@State var desiredNotificationsEnabled: Bool = false
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
#if os(iOS)
|
||||
Form {
|
||||
innerBody
|
||||
}
|
||||
#elseif os(macOS)
|
||||
List {
|
||||
innerBody
|
||||
}
|
||||
.listStyle(InsetListStyle())
|
||||
#endif
|
||||
}
|
||||
.task { viewModel.checkPushNotificationsStatus() }
|
||||
}
|
||||
|
||||
private var innerBody: some View {
|
||||
Group {
|
||||
Section {
|
||||
Toggle(isOn: $viewModel.desiredNotificationsEnabled, label: { Text("Notifications Enabled") })
|
||||
}.onChange(of: viewModel.desiredNotificationsEnabled) { _ in
|
||||
viewModel.tryUpdateToDesired()
|
||||
}
|
||||
|
||||
Section {
|
||||
Text("""
|
||||
Enabling push notifications gives Omnivore device permission to send notifications, \
|
||||
but you are in charge of which notifications are sent.
|
||||
|
||||
Push notifications are triggered using your \
|
||||
[account rules](https://omnivore.app/settings/rules) which you can edit online.
|
||||
""")
|
||||
.accentColor(.blue)
|
||||
}
|
||||
}
|
||||
.navigationTitle("Push Notifications")
|
||||
}
|
||||
}
|
||||
@ -6,7 +6,7 @@ import Views
|
||||
@MainActor final class RecommendationsGroupsViewModel: ObservableObject {
|
||||
@Published var isLoading = false
|
||||
@Published var isCreating = false
|
||||
@Published var networkError = false
|
||||
@Published var networkError = true
|
||||
@Published var recommendationGroups = [InternalRecommendationGroup]()
|
||||
|
||||
@Published var showCreateSheet = false
|
||||
@ -130,31 +130,14 @@ struct GroupsView: View {
|
||||
.disabled(viewModel.isLoading)
|
||||
}
|
||||
|
||||
if viewModel.recommendationGroups.count > 0 {
|
||||
Section(header: Text("Your recommendation groups")) {
|
||||
ForEach(viewModel.recommendationGroups) { recommendationGroup in
|
||||
NavigationLink(
|
||||
destination: RecommendationGroupView(viewModel: RecommendationsGroupViewModel(recommendationGroup: recommendationGroup))
|
||||
) {
|
||||
Text(recommendationGroup.name)
|
||||
}
|
||||
Section(header: Text("Your recommendation groups")) {
|
||||
ForEach(viewModel.recommendationGroups) { recommendationGroup in
|
||||
NavigationLink(
|
||||
destination: RecommendationGroupView(viewModel: RecommendationsGroupViewModel(recommendationGroup: recommendationGroup))
|
||||
) {
|
||||
Text(recommendationGroup.name)
|
||||
}
|
||||
}
|
||||
} else if !viewModel.isLoading {
|
||||
Section {
|
||||
Text("""
|
||||
You are not a member of any groups.
|
||||
Create a new group and send the invite link to your friends get started.
|
||||
|
||||
During the beta you are limited to creating three groups, and each group
|
||||
can have a maximum of twelve users.
|
||||
|
||||
[Learn more about groups](https://blog.omnivore.app/p/dca38ba4-8a74-42cc-90ca-d5ffa5d075cc)
|
||||
""")
|
||||
.accentColor(.blue)
|
||||
}
|
||||
} else {
|
||||
ProgressView()
|
||||
}
|
||||
}
|
||||
.navigationTitle("Recommendation Groups")
|
||||
|
||||
@ -49,12 +49,10 @@ struct InnerRootView: View {
|
||||
if authenticator.isLoggedIn {
|
||||
GeometryReader { geo in
|
||||
PrimaryContentView()
|
||||
.onAppear {
|
||||
viewModel.triggerPushNotificationRequestIfNeeded()
|
||||
}
|
||||
#if os(iOS)
|
||||
.miniPlayer()
|
||||
.formSheet(isPresented: $viewModel.showNewFeaturePrimer, modalSize: CGSize(width: geo.size.width * 0.66, height: geo.size.width * 0.66)) {
|
||||
.formSheet(isPresented: $viewModel.showNewFeaturePrimer,
|
||||
modalSize: CGSize(width: geo.size.width * 0.66, height: geo.size.width * 0.66)) {
|
||||
FeaturePrimer.recommendationsPrimer
|
||||
}
|
||||
.onAppear {
|
||||
|
||||
@ -35,32 +35,8 @@ public final class RootViewModel: ObservableObject {
|
||||
#endif
|
||||
}
|
||||
|
||||
func triggerPushNotificationRequestIfNeeded() {
|
||||
// guard FeatureFlag.enablePushNotifications else { return }
|
||||
//
|
||||
// if UserDefaults.standard.bool(forKey: UserDefaultKey.userHasDeniedPushPrimer.rawValue) {
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// #if os(iOS)
|
||||
// UNUserNotificationCenter.current().getNotificationSettings { [weak self] settings in
|
||||
// switch settings.authorizationStatus {
|
||||
// case .notDetermined:
|
||||
// DispatchQueue.main.async {
|
||||
// self?.showPushNotificationPrimer = true
|
||||
// }
|
||||
// case .authorized, .provisional, .ephemeral, .denied:
|
||||
// return
|
||||
// @unknown default:
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
// #endif
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
func handlePushNotificationPrimerAcceptance() {
|
||||
// showPushNotificationPrimer = false
|
||||
// UNUserNotificationCenter.current().requestAuth()
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -24,4 +24,5 @@ public enum UserDefaultKey: String {
|
||||
case audioPlayerExpanded
|
||||
case themeName
|
||||
case shouldShowNewFeaturePrimer
|
||||
case notificationsEnabled
|
||||
}
|
||||
|
||||
@ -47,6 +47,7 @@ private let logger = Logger(subsystem: "app.omnivore", category: "app-delegate")
|
||||
|
||||
Services.registerBackgroundFetch()
|
||||
configurePushNotifications()
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user