Skip to content

SwiftUIVolumeButtonsHandler provides an easy way to handle clicks on hardware volume buttons for SwiftUI projects that run on iOS devices.

License

Notifications You must be signed in to change notification settings

WarnerBros144/SwiftUIVolumeButtonsHandler

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftUIVolumeButtonsHandler

SwiftUIVolumeButtonsHandler is simple way to handling clicks on hardware volume buttons on iPhone or iPad.

Usage

Step 1: Declare the handler

let volumeButtonHandler = VolumeButtonHandler(containerView: UIView())

Step 2: Automatically start the handler by adding the overlay

.overlay(
    VolumeButtonHandlerView(volumeButtonHandler: volumeButtonHandler)
)

Step 3: Listen for button presses

.onAppear {
    volumeButtonHandler.buttonClosure = { button in
        switch button {
        case .up:
            print("Volume up button pressed")
            // execute your code for volume up button press here
        case .down:
            print("Volume down button pressed")
            // execute your code for volume down button press here
        }
    }
}

Installation

To install SwiftUIVolumeButtonsHandler, download the code as a zip file, then drag Log.swift and VolumeButtonHandler.swift into your project.

References

This project based on Objective-C code JPSVolumeButtonHandler

About

SwiftUIVolumeButtonsHandler provides an easy way to handle clicks on hardware volume buttons for SwiftUI projects that run on iOS devices.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 100.0%