Skip to content

Commit

Permalink
Add support for resetting Remote Messages for debugging purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoy committed Jul 12, 2024
1 parent 9ee9b37 commit 1caeeeb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
20 changes: 20 additions & 0 deletions Sources/RemoteMessaging/RemoteMessagingStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,26 @@ extension RemoteMessagingStore {
}
}
}

public func resetRemoteMessages() {
guard remoteMessagingAvailabilityProvider.isRemoteMessagingAvailable else {
return
}

let context = database.makeContext(concurrencyType: .privateQueueConcurrencyType, name: Constants.privateContextName)
context.performAndWait {
context.deleteAll(entityDescriptions: [
RemoteMessageManagedObject.entity(in: context),
RemoteMessagingConfigManagedObject.entity(in: context)
])

do {
try context.save()
} catch {
os_log("Failed to reset remote messages", log: log, type: .error)
}
}
}
}

// MARK: - RemoteMessageManagedObject Private Interface
Expand Down
6 changes: 5 additions & 1 deletion Sources/RemoteMessaging/RemoteMessagingStoring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@

import Foundation

public protocol RemoteMessagingStoring {
public protocol RemoteMessagingStoringDebuggingSupport {
func resetRemoteMessages()
}

public protocol RemoteMessagingStoring: RemoteMessagingStoringDebuggingSupport {

func saveProcessedResult(_ processorResult: RemoteMessagingConfigProcessor.ProcessorResult)
func fetchRemoteMessagingConfig() -> RemoteMessagingConfig?
Expand Down

0 comments on commit 1caeeeb

Please sign in to comment.