Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nixzhu/Proposer
Make permission request easier.
https://github.com/nixzhu/Proposer
Last synced: 6 days ago
JSON representation
Make permission request easier.
- Host: GitHub
- URL: https://github.com/nixzhu/Proposer
- Owner: nixzhu
- License: mit
- Created: 2015-07-10T17:51:00.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-12-17T07:06:46.000Z (almost 3 years ago)
- Last Synced: 2024-04-23T19:18:41.700Z (8 months ago)
- Language: Swift
- Homepage:
- Size: 65.4 KB
- Stars: 856
- Watchers: 14
- Forks: 50
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - Proposer - Make permission request easier (Supports Camera, Photos, Microphone, Contacts, Location). (Permissions / Other Parsing)
- awesome-ios-star - Proposer - Make permission request easier (Supports Camera, Photos, Microphone, Contacts, Location). (Permissions / Other Parsing)
README
# Proposer
Proposer provides a single API to request permission for access **Camera**, **Photos**, **Microphone**, **Contacts**, **Reminders**, **Calendar**, **Location** or **Notifications**.
## Requirements
Swift 4.2, iOS 9.0
(Swift 3, use version 1.1.0)
## Example
Only one single API:
```swift
proposeToAccess(_:agreed:rejected:)
```In real world:
```swift
import Proposer
``````swift
@IBAction func choosePhoto() {
let photos: PrivateResource = .photos
let propose: Propose = {
proposeToAccess(photos, agreed: {
print("I can access Photos. :]\n")
if UIImagePickerController.isSourceTypeAvailable(.savedPhotosAlbum) {
let imagePicker = UIImagePickerController()
imagePicker.sourceType = .savedPhotosAlbum
self.present(imagePicker, animated: true, completion: nil)
}
}, rejected: {
self.alertNoPermissionToAccess(photos)
})
}
showProposeMessageIfNeedFor(photos, andTryPropose: propose)
}
```When you want to get user's location, thanks to Swift's enum, you can even choose the usage mode:
```swift
@IBAction func shareLocation() {
let location: PrivateResource = .location(.whenInUse)
let propose: Propose = {
proposeToAccess(location, agreed: {
print("I can access Location. :]\n")
}, rejected: {
self.alertNoPermissionToAccess(location)
})
}
showProposeMessageIfNeedFor(location, andTryPropose: propose)
}
```Depending on your needs, you must add a `NSLocationWhenInUseUsageDescription` or `NSLocationAlwaysUsageDescription` to your Info.plist
See the demo for more information.
I recommend you add a `UIViewController+Proposer.swift` file (like the demo) for show localized alert before the first proposal or when propose failed.
## Installation
Feel free to drag `Proposer.swift` to your iOS Project. But it's recommended to use Carthage (or CocoaPods).
### Carthage
```ogdl
github "nixzhu/Proposer"
```#### CocoaPods
```ruby
pod 'Proposer'
```# Contact
NIX [@nixzhu](https://twitter.com/nixzhu)
## License
Proposer is available under the MIT license. See the LICENSE file for more info.