{"id":22477740,"url":"https://github.com/swiftuiux/grand-access","last_synced_at":"2025-12-11T22:54:34.124Z","repository":{"id":246658892,"uuid":"689923777","full_name":"swiftuiux/grand-access","owner":"swiftuiux","description":"Access permision camera, mic, cam in Swift kit These code are designed to help manage permission camera, permition contacts and display alerts within a SwiftUI application. Added permision for microphone Photo Library Support from ios 14","archived":false,"fork":false,"pushed_at":"2024-11-30T13:10:09.000Z","size":24754,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-26T12:07:53.144Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/swiftuiux.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-09-11T07:33:40.000Z","updated_at":"2025-09-04T13:31:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"657b4a7d-45c9-431e-91b4-7f909b75fcfe","html_url":"https://github.com/swiftuiux/grand-access","commit_stats":null,"previous_names":["the-igor/grand-access","igor11191708/grand-access","igor111917180/grand-access","swiftuiux/grand-access"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/swiftuiux/grand-access","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftuiux%2Fgrand-access","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftuiux%2Fgrand-access/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftuiux%2Fgrand-access/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftuiux%2Fgrand-access/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swiftuiux","download_url":"https://codeload.github.com/swiftuiux/grand-access/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftuiux%2Fgrand-access/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27672063,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-11T02:00:11.302Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ios","swift","swiftui"],"created_at":"2024-12-06T14:12:06.665Z","updated_at":"2025-12-11T22:54:34.104Z","avatar_url":"https://github.com/swiftuiux.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Grand access and Permission async/await\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fswiftuiux%2Fgrand-access%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/swiftuiux/grand-access)\n\n## Why ?! instead of a preface\nSo, while working on some projects, I kept running into designs that needed the rights request functions to be in different visual components. Instead of copying and pasting the same code everywhere, I decided to streamline things by pulling that functionality into its own package.\n\nI’ve decided to separate certain permission-acquiring functionalities within my projects because each type of permission has its unique implementation requirements. I might even consider placing each of them in a separate package. I will think about this later based on practical experience.\n\n### SwiftUI example\nThe project demonstrating how to handle camera permissions in an iOS application [here](https://github.com/swiftuiux/permission-swift-example)\n\n### CoreLocation\nExplore the [**Async location**](https://github.com/swiftuiux/d3-async-location) repository on GitHub. It provides practical examples on how to set up and manage permissions for location services in iOS applications.\n\n## Overview\n\nThis package contains two main components: `GrandAccessModifier` and `Permission`. These components are designed to help manage permissions and display alerts within a SwiftUI application.\n\n## Features\n\n### Request access for\n- **Camera**: iOS, macOS, tvOS (tvOS 17.0+)\n- **Contacts**: iOS, macOS, watchOS\n- **Microphone**: iOS, watchOS\n- **Photo Library**: iOS, macOS, tvOS\n\n### GrandAccessModifier\n- [x] Customizable Alert: Allows setting custom titles and messages for alerts.\n- [x] Settings Navigation: Provides a button to open the app’s settings directly from the alert.\n- [x] Compatibility: Supports iOS 14, macOS 11, tvOS 14, watchOS 7 and later versions with appropriate alert handling.\n\n### Permission\n- [x] Asynchronous Permission Handling: Uses async/await for checking and requesting permissions.\n- [x] Robust Error Handling: Includes basic error handling and logging for permission requests.\n\n\n ![simulate locations](https://github.com/swiftuiux/grand-access/blob/main/img/grand_access.gif)\n\n## Usage\n\n### GrandAccessModifier\n\nTo use `GrandAccessModifier`, apply it to any SwiftUI view. This modifier will display an alert when the `showingAlert` binding is set to `true`.\n\n#### Example:\n\n```swift\nimport SwiftUI\n\nstruct ContentView: View {\n    @State private var showingAlert = false\n\n    var body: some View {\n        VStack {\n            Text(\"Hello, World!\")\n                .modifier(GrandAccessModifier(\n                    title: \"Access Required\",\n                    message: \"This app requires access to your settings.\",\n                    showingAlert: $showingAlert\n                ))\n\n            Button(\"Show Alert\") {\n                showingAlert = true\n            }\n        }\n    }\n}\n```\n\n### Permission\n\n`Permission` provides asynchronous properties to check if access to contacts or the camera has been granted, and methods to request access if it hasn't.\n\n#### Example:\n\n##### Permission Keys and Descriptions\nAdd to Info.plist file to include the necessary permission descriptions:\n\n| NS Key | Key | Description |\n|--------|-----|-------------|\n| `NSCameraUsageDescription` | Privacy - Camera Usage Description| A string that describes why your app needs access to the camera. This is displayed in the permission dialog. |\n| `NSContactsUsageDescription` | Privacy - Contacts Usage Description| A string that explains why your app needs access to the user’s contacts. |\n| `NSMicrophoneUsageDescription` | Privacy - Microphone Usage Description| A string that details why your app requires access to the microphone. |\n| `NSPhotoLibraryUsageDescription` | Privacy - Photo Library Usage Description| A string that justifies why your app needs access to the photo library. |\n\n##### Example Descriptions:\n\n- **Camera**: \"This app uses the camera to let you take photos to personalize your profile.\"\n- **Contacts**: \"Access to contacts is used for quickly inviting your friends to join the app.\"\n- **Microphone**: \"The microphone access is needed for voice chats in your conversations.\"\n- **Photo Library**: \"This app accesses your photo library for uploading images to your account.\"\n\n```swift\n\nimport AVFoundation\nimport Contacts\nimport Photos\n\n// Check if contacts access is granted\nlet isContactsGranted = await Permission.isContactsGranted\n\n// Request contacts access if not granted\nif !isContactsGranted {\n    let granted = await Permission.requestContactsAccess\n    if granted {\n        // Access granted\n    } else {\n        // Access denied\n    }\n}\n\n// Similarly, check and request access for Camera, Microphone, and Photo Library\nlet isCameraGranted = await Permission.isCameraGranted\nlet isMicrophoneGranted = await Permission.isMicrophoneGranted\nlet isPhotoLibraryGranted = await Permission.isPhotoLibraryGranted\n```\n\n```swift\n\nimport SwiftUI\n\nstruct PermissionView: View {\n    @State private var isCameraGranted = false\n    @State private var isContactsGranted = false\n\n    var body: some View {\n        VStack {\n            Button(\"Check Camera Permission\") {\n                Task {\n                    isCameraGranted = await Permission.isCameraGranted\n                    print(\"Camera Access: \\(isCameraGranted)\")\n                }\n            }\n\n            Button(\"Check Contacts Permission\") {\n                Task {\n                    isContactsGranted = await Permission.isContactsGranted\n                    print(\"Contacts Access: \\(isContactsGranted)\")\n                }\n            }\n        }\n    }\n}\n```\n\n## Documentation\n\n### GrandAccessModifier\n\n| Var  | Description                                                |\n|-----------------|------------------------------------------------------------|\n| **title**       | The title of the alert.                                    |\n| **message**     | The main message of the alert.                             |\n| **showingAlert**| A binding to control the visibility of the alert.          |\n| **url**         | The URL to open when the settings button is pressed. Defaults to the app settings URL. |\n\n### Permission\n\n| Method                 | Description                                           | Access   |\n|-------------------------------|-------------------------------------------------------|----------|\n| **isContactsGranted**         | Checks if contacts access is granted.                 | public   |\n| **isCameraGranted**           | Checks if camera access is granted.                   | public   |\n| **isMicrophoneGranted**       | Checks if microphone access is granted.               | public   |\n| **isPhotoLibraryGranted**     | Checks if photo library access is granted.            | public   |\n| **requestContactsAccess**     | Requests access to contacts.        | internal |\n| **requestCameraAccess**       | Requests access to the camera.      | internal |\n| **requestMicrophoneAccess**   | Requests access to the microphone.  | internal |\n| **requestPhotoLibraryAccess** | Requests access to the photo library. | internal |\n\n\n## License\n\nThis project is licensed under the MIT License. See the LICENSE file for more details.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswiftuiux%2Fgrand-access","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswiftuiux%2Fgrand-access","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswiftuiux%2Fgrand-access/lists"}