feat(ios): implement isChannelEnabled, openChannelSettings, and checkStatus methods
Implemented status and settings methods matching Android functionality: isChannelEnabled(): - Checks if notifications are enabled (iOS doesn't have channels) - Returns enabled status and channelId - Uses UNUserNotificationCenter authorization status openChannelSettings(): - Opens iOS app notification settings - iOS doesn't have per-channel settings like Android - Opens general app settings instead - Returns opened status and channelId checkStatus(): - Comprehensive status check combining permissions and scheduling - Returns notificationsEnabled, isScheduled, scheduledCount, pendingCount - Includes nextNotificationTime and channel information - Combines multiple status checks into one call iOS Adaptations: - No notification channels (checks app-level authorization) - Opens app settings instead of channel settings - Uses UNUserNotificationCenter for status checks Progress: 27/52 methods implemented (52% complete - HALFWAY!)
This commit is contained in:
@@ -1012,6 +1012,125 @@ public class DailyNotificationPlugin: CAPPlugin {
|
||||
call.resolve()
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if channel is enabled
|
||||
*
|
||||
* iOS doesn't have notification channels like Android.
|
||||
* This checks if notifications are enabled for the app.
|
||||
*
|
||||
* Equivalent to Android's isChannelEnabled method.
|
||||
*/
|
||||
@objc func isChannelEnabled(_ call: CAPPluginCall) {
|
||||
let channelId = call.getString("channelId") ?? "daily_notification_channel"
|
||||
|
||||
print("DNP-PLUGIN: Checking channel enabled: \(channelId)")
|
||||
|
||||
notificationCenter.getNotificationSettings { settings in
|
||||
let enabled = settings.authorizationStatus == .authorized
|
||||
|
||||
let result: [String: Any] = [
|
||||
"enabled": enabled,
|
||||
"channelId": channelId
|
||||
]
|
||||
|
||||
DispatchQueue.main.async {
|
||||
call.resolve(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open channel settings
|
||||
*
|
||||
* Opens iOS notification settings for the app.
|
||||
* iOS doesn't have per-channel settings like Android.
|
||||
*
|
||||
* Equivalent to Android's openChannelSettings method.
|
||||
*/
|
||||
@objc func openChannelSettings(_ call: CAPPluginCall) {
|
||||
let channelId = call.getString("channelId") ?? "daily_notification_channel"
|
||||
|
||||
print("DNP-PLUGIN: Opening channel settings: \(channelId)")
|
||||
|
||||
// iOS doesn't have per-channel settings
|
||||
// Open app notification settings instead
|
||||
if let settingsUrl = URL(string: UIApplication.openSettingsURLString) {
|
||||
if UIApplication.shared.canOpenURL(settingsUrl) {
|
||||
UIApplication.shared.open(settingsUrl) { success in
|
||||
let result: [String: Any] = [
|
||||
"opened": success,
|
||||
"channelId": channelId
|
||||
]
|
||||
call.resolve(result)
|
||||
}
|
||||
} else {
|
||||
let result: [String: Any] = [
|
||||
"opened": false,
|
||||
"channelId": channelId,
|
||||
"error": "Cannot open settings URL"
|
||||
]
|
||||
call.resolve(result)
|
||||
}
|
||||
} else {
|
||||
let result: [String: Any] = [
|
||||
"opened": false,
|
||||
"channelId": channelId,
|
||||
"error": "Invalid settings URL"
|
||||
]
|
||||
call.resolve(result)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check status
|
||||
*
|
||||
* Comprehensive status check for notifications.
|
||||
* Returns permission status, scheduling status, and other relevant information.
|
||||
*
|
||||
* Equivalent to Android's checkStatus method.
|
||||
*/
|
||||
@objc func checkStatus(_ call: CAPPluginCall) {
|
||||
print("DNP-PLUGIN: Checking comprehensive status")
|
||||
|
||||
// Get notification authorization status
|
||||
notificationCenter.getNotificationSettings { settings in
|
||||
let notificationsEnabled = settings.authorizationStatus == .authorized
|
||||
|
||||
// Get notification status
|
||||
self.notificationCenter.getPendingNotificationRequests { requests in
|
||||
let dailyNotifications = requests.filter { $0.identifier.hasPrefix("daily_") }
|
||||
|
||||
// Get schedules from UserDefaults
|
||||
let schedules = self.getSchedulesFromUserDefaults()
|
||||
let notifySchedules = schedules.filter {
|
||||
($0["kind"] as? String) == "notify" &&
|
||||
($0["enabled"] as? Bool) == true
|
||||
}
|
||||
|
||||
// Calculate next notification time
|
||||
var nextNotificationTime: TimeInterval = 0
|
||||
if let nextRunTimes = notifySchedules.compactMap({ $0["nextRunTime"] as? TimeInterval }) as? [TimeInterval],
|
||||
!nextRunTimes.isEmpty {
|
||||
nextNotificationTime = nextRunTimes.min() ?? 0
|
||||
}
|
||||
|
||||
let result: [String: Any] = [
|
||||
"notificationsEnabled": notificationsEnabled,
|
||||
"isScheduled": !notifySchedules.isEmpty,
|
||||
"scheduledCount": notifySchedules.count,
|
||||
"pendingCount": dailyNotifications.count,
|
||||
"nextNotificationTime": nextNotificationTime,
|
||||
"channelId": "daily_notification_channel",
|
||||
"channelEnabled": notificationsEnabled
|
||||
]
|
||||
|
||||
DispatchQueue.main.async {
|
||||
call.resolve(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private Implementation Methods
|
||||
|
||||
private func setupBackgroundTasks() {
|
||||
|
||||
Reference in New Issue
Block a user