Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a debug menu action to reset Remote Messages on macOS #891

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Sources/RemoteMessaging/RemoteMessagingStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,27 @@ 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)
}
}
notificationCenter.post(name: Notifications.remoteMessagesDidChange, object: nil)
}
}

// 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
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,6 @@ public class MockRemoteMessagingStore: RemoteMessagingStoring {
public func updateRemoteMessage(withID id: String, asShown shown: Bool) {
updateRemoteMessageCalls += 1
}

public func resetRemoteMessages() {}
}
Loading