UIAppUtils is a robust UIKit utility library specializing in app-wide functionalities, designed to simplify app development.
- Retrieve app version and build numbers.
- Get the topmost view controller in the app's view hierarchy.
- Take a screenshot of the current key window.
- Open the Settings app or the app-specific settings.
- Check media permissions for camera and microphone.
- Request an app rating from the user.
To integrate UIAppUtils into your Xcode project using Swift Package Manager, follow these steps:
- Open your project in Xcode.
- Navigate to the menu bar and click
File
>Swift Packages
>Add Package Dependency...
. - In the search bar of the new window that appears, paste the following URL:
https://github.com/rayhaanalykhan/UIAppUtils.git
- Follow the on-screen instructions to choose the package options and the version you want to integrate.
- Once completed, Xcode will download the package and add it to your project navigator.
To use UIAppUtils in your project, you can call its static methods directly:
-
Retrieve App Version and Build:
Get the current version and build number of the app:
print("App Version: \(UIAppUtils.appVersion)")
print("App Build: \(UIAppUtils.appBuild)")
-
Get Topmost View Controller:
Retrieve the topmost view controller in the app's current key window's view hierarchy.
if let topVC = UIAppUtils.getTopMostViewController() { topVC.present(someVC, animated: true, completion: nil) } else { print("No view controller found.") }
// Alternate UIAppUtils.getTopMostViewController()?.present(UIViewController(), animated: true, completion: nil) // replace UIViewController() with the controller you want to show
-
Take a Screenshot:
Capture a screenshot of the app's current key window's view hierarchy.
if let screenshot = UIAppUtils.takeScreenshot() { // someImageView.image = screenshot print("Screenshot taken.") } else { print("Could not take screenshot.") }
// Alternate UIImageView().image = UIAppUtils.takeScreenshot() ?? UIImage() // replace UIImageView() with the your imageView.
-
Open Settings:
Open the main settings app or the app-specific settings.
UIAppUtils.goToSettingsApp() // Open the 'Settings' app of your device UIAppUtils.goToAppSettings() // Open the settings of your app
-
Check Media Permissions:
Check for camera or microphone permissions and handle the response.
The function handles all authorization statuses and shows appropriate alert messages for all cases (not determine, first-time denied, previously denied, restricted, and unknown).
UIAppUtils.checkMediaPermission(mediaType: .video) { granted in // video or audio permission if granted { print("Camera access granted.") } else { print("Camera access denied.") } }
-
Request App Review:
Prompt the user to rate your app.
UIAppUtils.requestReview()
UIAppUtils is released under the MIT License. See the LICENSE file for further details.
Contributors are welcomed to fork the project and submit pull requests. Please include unit tests if possible for any new or existing functionality. Also, update the README accordingly.
For further information, contact me via email rayhaanalykhan@gmail.com.