Add comprehensive offline bookmark support with sync capabilities: - Implement offline bookmark storage using Core Data with App Group sharing - Add Share Extension support for saving bookmarks when server unavailable - Create LocalBookmarksSyncView for managing offline bookmark queue - Add OfflineSyncManager for automatic and manual sync operations - Implement ServerConnectivity monitoring and status handling - Add badge notifications on More tab for pending offline bookmarks - Fix tag pagination in Share Extension with unique IDs for proper rendering - Update PhoneTabView with event-based badge count updates - Add App Group entitlements for data sharing between main app and extension The offline system provides seamless bookmark saving when disconnected, with automatic sync when connection is restored and manual sync options.
42 lines
1.2 KiB
Swift
42 lines
1.2 KiB
Swift
import CoreData
|
|
import Foundation
|
|
|
|
class CoreDataManager {
|
|
static let shared = CoreDataManager()
|
|
|
|
private init() {}
|
|
|
|
lazy var persistentContainer: NSPersistentContainer = {
|
|
let container = NSPersistentContainer(name: "readeck")
|
|
|
|
// Use App Group container for shared access with extensions
|
|
let storeURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.readeck.app")?.appendingPathComponent("readeck.sqlite")
|
|
|
|
if let storeURL = storeURL {
|
|
let storeDescription = NSPersistentStoreDescription(url: storeURL)
|
|
container.persistentStoreDescriptions = [storeDescription]
|
|
}
|
|
|
|
container.loadPersistentStores { _, error in
|
|
if let error = error {
|
|
fatalError("Core Data error: \(error)")
|
|
}
|
|
}
|
|
return container
|
|
}()
|
|
|
|
var context: NSManagedObjectContext {
|
|
return persistentContainer.viewContext
|
|
}
|
|
|
|
func save() {
|
|
if context.hasChanges {
|
|
do {
|
|
try context.save()
|
|
} catch {
|
|
print("Failed to save Core Data context: \(error)")
|
|
}
|
|
}
|
|
}
|
|
}
|