An external drive / volume can be connected to an iPad. I want to be able to take an action in my app when this happens and my app is in the foreground - say for example bringing up an import dialog.
On macOS I can write the following to get a notification that a volume has mounted and take an action - here in this basic example I set a property to true:
struct SomeViewOfMine: View {
@State private var importDialogVisible = false
private var cancellable: Set<AnyCancellable>()
init() {
NSWorkspace.shared.notificationCenter.publisher(for: NSWorkspace.didMountNotification)
.sink { _ in
self.importDialogVisible = true
}
.store(in: &cancellable)
}
// Other code in my view here
}
But I can't find the same functionality within iOS. Am I missing something or is there a way to achieve this?