Latest | 4.0 |
---|---|
Homepage | https://github.com/IvanVorobei/RequestPermission |
License | MIT |
Platforms | ios 10.0, requires ARC |
Authors |
About
Request permissions with dialog. You can request many permissions at once. I do UI of dialog in Apple style. If you need additional permission, please, create new issue.
Watch timelaps how I design UI for this pod on YouTube.
If you like the project, do not forget to put star ★
or help me by donate:
See project’s backers in Sponsors section.
Navigate
- Requirements
- Installation
- Usage
- Permissions
- Customisation
- Delegate
- String in Info.plist
- How I do UI
- Sponsors
- Other Projects +gif
- License
- Contact or Order Develop
Requirements
Swift 4.2
& 5.0
. Ready for use on iOS 10+
Installation
CocoaPods:
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate SPPermission
into your Xcode project using CocoaPods, specify it in your Podfile
:
pod 'SPPermission/Notification'
Due to Apple’s new policy regarding permission access you need to specifically define what kind of permissions you want to access using subspecs. For example if you want to access Camera
, Location
& Microphone
you define the following:
pod 'SPPermission/Camera'
pod 'SPPermission/Location'
pod 'SPPermission/Microphone'
Available subspecs
“`ruby
pod ‘SPPermission/Camera’
“`
“`ruby
pod ‘SPPermission/Contacts’
“`
“`ruby
pod ‘SPPermission/Calendar’
“`
“`ruby
pod ‘SPPermission/PhotoLibrary’
“`
“`ruby
pod ‘SPPermission/Notification’
“`
“`ruby
pod ‘SPPermission/Microphone’
“`
“`ruby
pod ‘SPPermission/Reminders’
“`
“`ruby
pod ‘SPPermission/SpeechRecognizer’
“`
“`ruby
pod ‘SPPermission/Location’
“`
“`ruby
pod ‘SPPermission/Motion’
“`
“`ruby
pod ‘SPPermission/MediaLibrary’
“`
Carthage
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate SPPermission
into your Xcode project using Carthage, specify it in your Cartfile
:
github "ivanvorobei/SPPermission"
As a workaround, you can provide custom build flags before building the dynamic framework to only compile
with permissions you request. This is done by adding a configuration file PermissionConfiguration.xcconfig
to the root of your project.
Manually
If you prefer not to use any of the aforementioned dependency managers, you can integrate SPPermission
into your project manually. Put Source/SPPermission
folder in your Xcode project. Make sure to enable Copy items if needed
and Create groups
.
After it need implement configuration file. See example project and config file PermissionConfiguration.xcconfig.
Usage
Call SPPermission
and use func request()
. Also, pass the controller on which the dialog should present:
import UIKit
import SPPermission
class ViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
SPPermission.Dialog.request(with: [.camera, .microphone, .notification], on: self)
}
}
If you want to know if permission is allowed, you need to call the function:
let isAllowedCamera = SPPermission.isAllowed(.camera)
let isDeniedMicrophone = SPPermission.isDenied(.microphone)
To learn how to customize titles and images you can read section Customisation
Permissions
If you want to request notification (or other permissions) without dialog, use the function:
SPPermission.request(.notification, with: {
// Callback
})
If you want add new permission, create issue.
Customisation
Protocol
If you want to change the text, you need to implement SPPermissionDialogDataSource
protocol. Override needed parameters to see the changes:
extension Controller: SPPermissionDialogDataSource {
var showCloseButton: Bool {
return true
}
}
And pass the object to the function:
SPPermission.Dialog.request(
with: [.photoLibrary, .contacts],
on: self,
delegate: self,
dataSource: self
)
Texts
All properties and functions optional. Func can return nil
. If do it – will be used defualt value.
extension Controller: SPPermissionDialogDataSource {
var dialogTitle: String { return "Need Permissions" }
var dialogSubtitle: String { return "Permissions Request" }
var dialogComment: String { return "Push are not required permissions" }
var allowTitle: String { return "Allow" }
var allowedTitle: String { return "Allowed" }
var bottomComment: String { return "" }
func name(for permission: SPPermissionType) -> String? { return nil }
func description(for permission: SPPermissionType) -> String? { return nil }
func deniedTitle(for permission: SPPermissionType) -> String? { return nil }
func deniedSubtitle(for permission: SPPermissionType) -> String? { return nil }
var cancelTitle: String { return "Cancel" }
var settingsTitle: String { return "Settings" }
}
Close Button
For add or remove close button, you need to override parameter showCloseButton
. Without button you’ll have to swipe the dialog to close it.
var showCloseButton: Bool {
return true
}
To see what it looks like, see the picture below:
Drag
For disable drag ovveride dragEnabled
. If need allow drag, but disable swipe for hide, ovveride dragToDismiss
:
var dragEnabled: Bool {
return true
}
var dragToDismiss: Bool {
return true
}
Colors
If you want to change the color scheme, you need to implement the protocol SPPermissionDialogColorSource
. It is not necessary to override all parameters, you can only change those that are necessary:
@objc public protocol SPPermissionDialogColorSource: class {
@objc optional var whiteColor: UIColor { get }
@objc optional var blackColor: UIColor { get }
@objc optional var baseColor: UIColor { get }
@objc optional var grayColor: UIColor { get }
@objc optional var lightGrayColor: UIColor { get }
@objc optional var iconWhiteColor: UIColor { get }
@objc optional var iconLightColor: UIColor { get }
@objc optional var iconMediumColor: UIColor { get }
@objc optional var iconDarkColor: UIColor { get }
@objc optional var closeIconBackgroundColor: UIColor { get }
@objc optional var closeIconColor: UIColor { get }
}
Will auto check SPPermissionDialogDataSource
also implement SPPermissionDialogColorSource
. You need pass for dataSource
object, which implements two protocols.
Start position
Property startTransitionYoffset
customise position before start. Set to 0 if need disable wobble animation. By default used center.y * 1.2
.
var startTransitionYoffset: CGFloat {
return 0
}
Delegate
To track events of hiding & allowing permissions associated with SPPermission
, implement protocol SPPermissionDialogDelegate
:
@objc public protocol SPPermissionDialogDelegate: class {
@objc optional func didHide()
@objc optional func didAllow(permission: SPPermissionType)
@objc optional func didDenied(permission: SPPermissionType)
}
And pass the delegate to the function:
SPPermission.Dialog.request(
with: [.calendar, .microphone],
on: self,
delegate: self
)
String in Info.plist
You need to add some strings to the Info.plist
file with description. List of keys:
- NSCameraUsageDescription
- NSContactsUsageDescription
- NSCalendarsUsageDescription
- NSMicrophoneUsageDescription
- NSAppleMusicUsageDescription
- NSSpeechRecognitionUsageDescription
- NSMotionUsageDescription
- NSLocationWhenInUseUsageDescription
- NSLocationAlwaysAndWhenInUseUsageDescription
- NSLocationAlwaysUsageDescription (iOS 10 and earlier)
Do not use the description as the name of the key – this causes errors in the latest version of the new Xcode.
How I do UI
I develop SPPermission
in Apple-way. For this, I check 30 apps to get UI-elements for it project. I am take screenshoot and draw it in Sketch. For example, Allow
button is similar to Get
button in the AppStore. Check timelapse to see how I am design SPPermission
:
Sponsors
Support me with a monthly donation and help me continue activities. After payment I add you to list of sponsor in my all projects with link to your profile. Become a sponsors
My projects
SPStorkController
SPStorkController is сontroller as in Apple Music, Podcasts and Mail apps. Simple adding close button and centering arrow indicator. Customizable height. Using custom TransitionDelegate. Check scroll’s bounce for more interactive. Simple adding close button and centering arrow indicator. You can download example Debts – Spending tracker app from AppStore.
Alert you can find in SPAlert project. If you want to buy source code of app in preview, please, go to xcode-shop.com
SPAlert
SPAlert is popup from Apple Music & Feedback in AppStore. Contains Done
& Heart
presets. Done
present with draw path animation. I clone Apple’s alerts as much as possible.
You can find this alerts in AppStore after feedback, after added song to library in Apple Music. I am also add alert without icon, as simple message.
You can download example Debts – Spending tracker app from AppStore. If you want to buy source code of app in preview, please, go to xcode-shop.com.
SPLarkController
SPLarkController transition between controllers. Translate to top. Make settings screen for application. You can add buttons and switches. The amount cells is not limited. You can start using project with just two lines of code and easy customisation. For implement settings as in preiew, see section Settings Controller.
You can download example app Code – Learn Swift & Design from AppStore. If you want to buy source code of app this app, please, go to xcode-shop.com.
License
SPPermission
is released under the MIT license. Check LICENSE.md
for details.
Contact
If you need any application or UI to be developed, message me at [email protected] or via telegram. I develop iOS apps and designs. I use swift
for development. To request more functionality, you should create a new issue. You can see my apps in AppStore.
Latest podspec
{ "name": "SPPermission", "version": "4.0", "summary": "Request permissions with dialog. For customise implement DataSource protocol. Check permissions.", "homepage": "https://github.com/IvanVorobei/RequestPermission", "source": { "git": "https://github.com/IvanVorobei/RequestPermission.git", "tag": "4.0" }, "license": { "type": "MIT", "file": "LICENSE" }, "authors": { "Ivan Vorobei": "[email protected]" }, "platforms": { "ios": "10.0" }, "ios": { "frameworks": "UIKit" }, "swift_versions": [ "4.2", "5.0" ], "requires_arc": true, "default_subspecs": "Core", "subspecs": [ { "name": "Core", "source_files": "Source/SPPermission/**/*.swift" }, { "name": "Camera", "dependencies": { "SPPermission/Core": [] }, "pod_target_xcconfig": { "SWIFT_ACTIVE_COMPILATION_CONDITIONS": "SPPERMISSION_CAMERA" } }, { "name": "PhotoLibrary", "dependencies": { "SPPermission/Core": [] }, "pod_target_xcconfig": { "SWIFT_ACTIVE_COMPILATION_CONDITIONS": "SPPERMISSION_PHOTOLIBRARY" } }, { "name": "Notification", "dependencies": { "SPPermission/Core": [] }, "pod_target_xcconfig": { "SWIFT_ACTIVE_COMPILATION_CONDITIONS": "SPPERMISSION_NOTIFICATION" } }, { "name": "Microphone", "dependencies": { "SPPermission/Core": [] }, "pod_target_xcconfig": { "SWIFT_ACTIVE_COMPILATION_CONDITIONS": "SPPERMISSION_MICROPHONE" } }, { "name": "Calendar", "dependencies": { "SPPermission/Core": [] }, "pod_target_xcconfig": { "SWIFT_ACTIVE_COMPILATION_CONDITIONS": "SPPERMISSION_CALENDAR" } }, { "name": "Contacts", "dependencies": { "SPPermission/Core": [] }, "pod_target_xcconfig": { "SWIFT_ACTIVE_COMPILATION_CONDITIONS": "SPPERMISSION_CONTACTS" } }, { "name": "Reminders", "dependencies": { "SPPermission/Core": [] }, "pod_target_xcconfig": { "SWIFT_ACTIVE_COMPILATION_CONDITIONS": "SPPERMISSION_REMINDERS" } }, { "name": "SpeechRecognizer", "dependencies": { "SPPermission/Core": [] }, "pod_target_xcconfig": { "SWIFT_ACTIVE_COMPILATION_CONDITIONS": "SPPERMISSION_SPEECH" } }, { "name": "Location", "dependencies": { "SPPermission/Core": [] }, "pod_target_xcconfig": { "SWIFT_ACTIVE_COMPILATION_CONDITIONS": "SPPERMISSION_LOCATION" } }, { "name": "Motion", "dependencies": { "SPPermission/Core": [] }, "pod_target_xcconfig": { "SWIFT_ACTIVE_COMPILATION_CONDITIONS": "SPPERMISSION_MOTION" } }, { "name": "MediaLibrary", "dependencies": { "SPPermission/Core": [] }, "pod_target_xcconfig": { "SWIFT_ACTIVE_COMPILATION_CONDITIONS": "SPPERMISSION_MEDIALIBRARY" } } ], "swift_version": "5.0" }
Tue, 11 Jun 2019 10:06:05 +0000