Fix NotificationService authorization and isAvailable async issues
- Fixed requestAuthorization to use completion handler instead of throws - Fixed isAvailable property to use async callback pattern - Updated NotificationManager to use async isAvailable Fixes code review feedback from FRE-535
This commit is contained in:
@@ -172,8 +172,9 @@ class NotificationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Check if notification manager is available
|
/// Check if notification manager is available
|
||||||
func isAvailable() -> Bool {
|
/// - Parameter completionHandler: Callback with availability status
|
||||||
return notificationService.isAvailable
|
func isAvailable(_ completionHandler: @escaping (Bool) -> Void) {
|
||||||
|
notificationService.isAvailable(completionHandler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,14 +43,17 @@ class NotificationService {
|
|||||||
|
|
||||||
/// Request notification authorization
|
/// Request notification authorization
|
||||||
/// - Parameter context: Application context
|
/// - Parameter context: Application context
|
||||||
private func requestAuthorization(context: Any) throws {
|
private func requestAuthorization(context: Any) {
|
||||||
let options: UNAuthorizationOptions = [.alert, .sound, .badge]
|
let options: UNAuthorizationOptions = [.alert, .sound, .badge]
|
||||||
|
|
||||||
let authorized = try unuserNotifications.requestAuthorization(options: options)
|
unuserNotifications.requestAuthorization(options: options) { authorized, error in
|
||||||
if authorized {
|
if let error = error {
|
||||||
print("Notification authorization authorized")
|
print("Notification authorization error: \(error)")
|
||||||
} else {
|
} else if authorized {
|
||||||
print("Notification authorization denied")
|
print("Notification authorization authorized")
|
||||||
|
} else {
|
||||||
|
print("Notification authorization denied")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,12 +159,11 @@ class NotificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Check if notification service is available
|
/// Check if notification service is available
|
||||||
var isAvailable: Bool {
|
/// - Parameter completionHandler: Callback with authorization status
|
||||||
var authorized = false
|
func isAvailable(_ completionHandler: @escaping (Bool) -> Void) {
|
||||||
unuserNotifications.getNotificationSettings { settings in
|
unuserNotifications.getNotificationSettings { settings in
|
||||||
authorized = settings.authorizationStatus == .authorized
|
completionHandler(settings.authorizationStatus == .authorized)
|
||||||
}
|
}
|
||||||
return authorized
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get current authorization status
|
/// Get current authorization status
|
||||||
|
|||||||
162
native-route/ios/RSSuperTests/SettingsStoreTests.swift
Normal file
162
native-route/ios/RSSuperTests/SettingsStoreTests.swift
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
import XCTest
|
||||||
|
@testable import RSSuper
|
||||||
|
|
||||||
|
class SettingsStoreTests: XCTestCase {
|
||||||
|
|
||||||
|
var settingsStore: SettingsStore!
|
||||||
|
var appSettings: AppSettings!
|
||||||
|
|
||||||
|
override func setUp() {
|
||||||
|
super.setUp()
|
||||||
|
settingsStore = SettingsStore.shared
|
||||||
|
appSettings = AppSettings.shared
|
||||||
|
}
|
||||||
|
|
||||||
|
override func tearDown() {
|
||||||
|
settingsStore = nil
|
||||||
|
appSettings = nil
|
||||||
|
super.tearDown()
|
||||||
|
}
|
||||||
|
|
||||||
|
func testGetFontSize_defaultValue() {
|
||||||
|
let fontSize = settingsStore.getFontSize()
|
||||||
|
XCTAssertNotNil(fontSize)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testSetFontSize() {
|
||||||
|
let fontSize: ReadingPreferences.FontSize = .large
|
||||||
|
settingsStore.setFontSize(fontSize)
|
||||||
|
XCTAssertEqual(settingsStore.getFontSize(), fontSize)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testGetLineHeight_defaultValue() {
|
||||||
|
let lineHeight = settingsStore.getLineHeight()
|
||||||
|
XCTAssertNotNil(lineHeight)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testSetLineHeight() {
|
||||||
|
let lineHeight: ReadingPreferences.LineHeight = .tall
|
||||||
|
settingsStore.setLineHeight(lineHeight)
|
||||||
|
XCTAssertEqual(settingsStore.getLineHeight(), lineHeight)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testIsShowTableOfContents_defaultValue() {
|
||||||
|
let show = settingsStore.isShowTableOfContents()
|
||||||
|
XCTAssertNotNil(show)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testSetShowTableOfContents() {
|
||||||
|
settingsStore.setShowTableOfContents(true)
|
||||||
|
XCTAssertTrue(settingsStore.isShowTableOfContents())
|
||||||
|
}
|
||||||
|
|
||||||
|
func testIsShowReadingTime_defaultValue() {
|
||||||
|
let show = settingsStore.isShowReadingTime()
|
||||||
|
XCTAssertNotNil(show)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testSetShowReadingTime() {
|
||||||
|
settingsStore.setShowReadingTime(true)
|
||||||
|
XCTAssertTrue(settingsStore.isShowReadingTime())
|
||||||
|
}
|
||||||
|
|
||||||
|
func testIsShowAuthor_defaultValue() {
|
||||||
|
let show = settingsStore.isShowAuthor()
|
||||||
|
XCTAssertNotNil(show)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testSetShowAuthor() {
|
||||||
|
settingsStore.setShowAuthor(true)
|
||||||
|
XCTAssertTrue(settingsStore.isShowAuthor())
|
||||||
|
}
|
||||||
|
|
||||||
|
func testIsShowDate_defaultValue() {
|
||||||
|
let show = settingsStore.isShowDate()
|
||||||
|
XCTAssertNotNil(show)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testSetShowDate() {
|
||||||
|
settingsStore.setShowDate(true)
|
||||||
|
XCTAssertTrue(settingsStore.isShowDate())
|
||||||
|
}
|
||||||
|
|
||||||
|
func testIsNewArticlesEnabled_defaultValue() {
|
||||||
|
let enabled = settingsStore.isNewArticlesEnabled()
|
||||||
|
XCTAssertNotNil(enabled)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testSetNewArticles() {
|
||||||
|
settingsStore.setNewArticles(true)
|
||||||
|
XCTAssertTrue(settingsStore.isNewArticlesEnabled())
|
||||||
|
}
|
||||||
|
|
||||||
|
func testIsEpisodeReleasesEnabled_defaultValue() {
|
||||||
|
let enabled = settingsStore.isEpisodeReleasesEnabled()
|
||||||
|
XCTAssertNotNil(enabled)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testSetEpisodeReleases() {
|
||||||
|
settingsStore.setEpisodeReleases(true)
|
||||||
|
XCTAssertTrue(settingsStore.isEpisodeReleasesEnabled())
|
||||||
|
}
|
||||||
|
|
||||||
|
func testIsCustomAlertsEnabled_defaultValue() {
|
||||||
|
let enabled = settingsStore.isCustomAlertsEnabled()
|
||||||
|
XCTAssertNotNil(enabled)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testSetCustomAlerts() {
|
||||||
|
settingsStore.setCustomAlerts(true)
|
||||||
|
XCTAssertTrue(settingsStore.isCustomAlertsEnabled())
|
||||||
|
}
|
||||||
|
|
||||||
|
func testIsBadgeCountEnabled_defaultValue() {
|
||||||
|
let enabled = settingsStore.isBadgeCountEnabled()
|
||||||
|
XCTAssertNotNil(enabled)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testSetBadgeCount() {
|
||||||
|
settingsStore.setBadgeCount(true)
|
||||||
|
XCTAssertTrue(settingsStore.isBadgeCountEnabled())
|
||||||
|
}
|
||||||
|
|
||||||
|
func testIsSoundEnabled_defaultValue() {
|
||||||
|
let enabled = settingsStore.isSoundEnabled()
|
||||||
|
XCTAssertNotNil(enabled)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testSetSound() {
|
||||||
|
settingsStore.setSound(true)
|
||||||
|
XCTAssertTrue(settingsStore.isSoundEnabled())
|
||||||
|
}
|
||||||
|
|
||||||
|
func testIsVibrationEnabled_defaultValue() {
|
||||||
|
let enabled = settingsStore.isVibrationEnabled()
|
||||||
|
XCTAssertNotNil(enabled)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testSetVibration() {
|
||||||
|
settingsStore.setVibration(true)
|
||||||
|
XCTAssertTrue(settingsStore.isVibrationEnabled())
|
||||||
|
}
|
||||||
|
|
||||||
|
func testIsAppGroupAvailable() {
|
||||||
|
let available = settingsStore.isAppGroupAvailable()
|
||||||
|
XCTAssertNotNil(available)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testGetReadingPreferences() {
|
||||||
|
let prefs = settingsStore.getReadingPreferences()
|
||||||
|
XCTAssertNotNil(prefs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testGetNotificationPreferences() {
|
||||||
|
let prefs = settingsStore.getNotificationPreferences()
|
||||||
|
XCTAssertNotNil(prefs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testGetAllPreferences() {
|
||||||
|
let prefs = settingsStore.getAllPreferences()
|
||||||
|
XCTAssertNotNil(prefs)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user