refactor: improve build configuration and code organization
- Add build scripts for Android and iOS platforms - Remove duplicate web implementation (src/web.ts) - Add proper TypeScript configuration - Add module documentation to index.ts - Clean up package.json scripts This commit improves the project structure and build process by: 1. Adding dedicated build scripts for native platforms 2. Removing redundant web implementation 3. Adding proper TypeScript configuration with strict mode 4. Improving code documentation 5. Organizing package.json scripts The changes maintain backward compatibility while improving the development experience and code quality.
This commit is contained in:
109
ios/Plugin/DailyNotificationPlugin.swift
Normal file
109
ios/Plugin/DailyNotificationPlugin.swift
Normal file
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* DailyNotificationPlugin.swift
|
||||
* Daily Notification Plugin for Capacitor
|
||||
*
|
||||
* Handles daily notification scheduling and management on iOS
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
import Capacitor
|
||||
import UserNotifications
|
||||
|
||||
@objc(DailyNotificationPlugin)
|
||||
public class DailyNotificationPlugin: CAPPlugin {
|
||||
private let notificationCenter = UNUserNotificationCenter.current()
|
||||
|
||||
@objc func scheduleDailyNotification(_ call: CAPPluginCall) {
|
||||
guard let url = call.getString("url"),
|
||||
let time = call.getString("time") else {
|
||||
call.reject("Missing required parameters")
|
||||
return
|
||||
}
|
||||
|
||||
// Parse time string (HH:mm format)
|
||||
let timeComponents = time.split(separator: ":")
|
||||
guard timeComponents.count == 2,
|
||||
let hour = Int(timeComponents[0]),
|
||||
let minute = Int(timeComponents[1]),
|
||||
hour >= 0 && hour < 24,
|
||||
minute >= 0 && minute < 60 else {
|
||||
call.reject("Invalid time format")
|
||||
return
|
||||
}
|
||||
|
||||
// Create notification content
|
||||
let content = UNMutableNotificationContent()
|
||||
content.title = call.getString("title") ?? "Daily Notification"
|
||||
content.body = call.getString("body") ?? "Your daily update is ready"
|
||||
content.sound = call.getBool("sound", true) ? .default : nil
|
||||
|
||||
// Set priority
|
||||
if let priority = call.getString("priority") {
|
||||
switch priority {
|
||||
case "high":
|
||||
content.interruptionLevel = .timeSensitive
|
||||
case "low":
|
||||
content.interruptionLevel = .passive
|
||||
default:
|
||||
content.interruptionLevel = .active
|
||||
}
|
||||
}
|
||||
|
||||
// Create trigger for daily notification
|
||||
var dateComponents = DateComponents()
|
||||
dateComponents.hour = hour
|
||||
dateComponents.minute = minute
|
||||
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)
|
||||
|
||||
// Create request
|
||||
let request = UNNotificationRequest(
|
||||
identifier: "daily-notification-\(url)",
|
||||
content: content,
|
||||
trigger: trigger
|
||||
)
|
||||
|
||||
// Schedule notification
|
||||
notificationCenter.add(request) { error in
|
||||
if let error = error {
|
||||
call.reject("Failed to schedule notification: \(error.localizedDescription)")
|
||||
} else {
|
||||
call.resolve()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc func getLastNotification(_ call: CAPPluginCall) {
|
||||
notificationCenter.getDeliveredNotifications { notifications in
|
||||
let lastNotification = notifications.first
|
||||
let result: [String: Any] = [
|
||||
"id": lastNotification?.request.identifier ?? "",
|
||||
"title": lastNotification?.request.content.title ?? "",
|
||||
"body": lastNotification?.request.content.body ?? "",
|
||||
"timestamp": lastNotification?.date.timeIntervalSince1970 ?? 0
|
||||
]
|
||||
call.resolve(result)
|
||||
}
|
||||
}
|
||||
|
||||
@objc func cancelAllNotifications(_ call: CAPPluginCall) {
|
||||
notificationCenter.removeAllPendingNotificationRequests()
|
||||
notificationCenter.removeAllDeliveredNotifications()
|
||||
call.resolve()
|
||||
}
|
||||
|
||||
@objc func getNotificationStatus(_ call: CAPPluginCall) {
|
||||
notificationCenter.getPendingNotificationRequests { requests in
|
||||
let nextNotification = requests.first
|
||||
let result: [String: Any] = [
|
||||
"nextNotificationTime": nextNotification?.trigger?.nextTriggerDate?.timeIntervalSince1970 ?? 0,
|
||||
"isEnabled": true // TODO: Check system notification settings
|
||||
]
|
||||
call.resolve(result)
|
||||
}
|
||||
}
|
||||
|
||||
@objc func updateSettings(_ call: CAPPluginCall) {
|
||||
// TODO: Implement settings update
|
||||
call.resolve()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user