jevonmao / permissionsswiftui Goto Github PK
View Code? Open in Web Editor NEWA SwiftUI package to beautifully display and handle permissions.
Home Page: https://jevonmao.github.io/PermissionsSwiftUI/
License: MIT License
A SwiftUI package to beautifully display and handle permissions.
Home Page: https://jevonmao.github.io/PermissionsSwiftUI/
License: MIT License
If possible, we should refactor over 40 modifiers for customizing the title and description of individual permissions into 1 single modifier. Ex. .setPermissionTextTo(for permission:[Enum], to title:String)
The enum should reflect a type for all permissions.
However, we won't fix this until ready for a major release. This will cause major API changes.
Parse Jazzy doc's json file for coverage percent
Is your feature request related to a problem? Please describe.
I am building an app for iOS 14 but this package is only available for iOS 13.
Describe the solution you'd like
Update this package for use with iOS 14 in Package.swift
.
Describe alternatives you've considered
No alternatives yet.
Additional context
N/A.
Hi, I've set up my iOS app to ask for permissions like so:
.JMModal(showModal: self.$showModal, for: [.locationAlways, .notification])
Allowing location successfully changes button to allowed, but allowing push notifications does not change the button to allowed, therefore, I cannot exit the modal.
However, I do see printouts in my appDelegate's didRegisterForRemoteNotificationsWithDeviceToken: saying that I have successfully registered? Everytime I click allow I see the button. I only see the Apple alert for allowing push notifications the very first time. But, button does not change to allowed.
To Reproduce
Steps to reproduce the behavior:
push notifications should change button to allowed and be able to dismiss.
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context
Add any other context about the problem here.
An overview description of this task, along with a reference to the actual bug or feature issue like: tracking feature #72
.
Put all the instructional images, visuals, and prototypes here for reference.
Add special instructions, warnings, previous issues, and other related stuff here, if applicable.
An overview description of this task, along with a reference to the actual bug or feature issue like: tracking feature #72
.
Put all the instructional images, visuals, and prototypes here for reference.
Add special instructions, warnings, previous issues, and other related stuff here, if applicable.
An overview description of this task, along with a reference to the actual bug or feature issue like: tracking feature #72
.
Put all the instructional images, visuals, and prototypes here for reference.
Add special instructions, warnings, previous issues, and other related stuff here, if applicable.
Inline documentation for all the public classes, structs, and methods.
We should use a struct to encapsulate health permission case in PermissionType
enum's associated value.
Because health permission is special and involves specific read
and write
permissions, the associated values for the health enum case can have different possibilities. Swift does not allow enum overloading, so its best to use a structure to encapsulate the information. Reference code snippets in Visual References section.
PermissionType
enumThe current declaration for health permission case looks like this:
case health(toShare: Set<HKSampleType>, read: Set<HKSampleType>)
Both toShare
and read
are non-optional associated values. However, this unnecessarily complicates situations where developers want read and write permission for all the enum cases.
Currently, there is no flexibility and toShare
and read
parameter must have values, even if they duplicate
//Duplicated code for toShare and read parameters
[.health(toShare: Set([HKSampleType.quantityType(forIdentifier: .activeEnergyBurned)!]),
read: Set([HKSampleType.quantityType(forIdentifier: .activeEnergyBurned)!]))]
This is the goal:
//Overloading HKAccess initializer
[.health(HKAccess(read: ..., write: ...)]
[.health(HKAccess(write: ...)]
[.health(HKAccess(readAndWrite: ...)]
N/A
Will use the UI popup alert design from #12. Suggested by Redditor.
Using AnyView is bad practice, and if it can be replaced (and I believe it can in this case) it should be. With just a few changes, MainView.swift would be modified to look like this:
struct MainView<BodyView: View>: View {
private var showModal: Binding<Bool>
private var bodyView: BodyView
init(for bodyView: BodyView, show showModal: Binding<Bool>) {
self.bodyView = bodyView
self.showModal = showModal
}
var body: some View {
bodyView
.sheet(isPresented: showModal, content: {
ModalView(showModal: showModal)
})
}
}
AnyView is used in many places and most (if not all) of them can be replaced with generics. This won't break anyone's existing code either, the type will not be MainView, it will be MainView<AnyView>. AnyView should be switched for generics in JMPermission (for the imageIcon) as well. This helps SwiftUI update views more efficiently and prevents always casting the image to AnyView like is currently in the README:
.setPermissionComponent(for: .camera,
image: AnyView(Image(systemName: "camera.fill")),
title: "Camcorder",
description: "App needs to record videos")
An overview description of this task, along with a reference to the actual bug or feature issue like: tracking feature #72
.
Put all the instructional images, visuals, and prototypes here for reference.
Add special instructions, warnings, previous issues, and other related stuff here, if applicable.
Hello,
My app got rejected because the X button in the modal doesn't work. Looking at 1.3.0, I see restrictDismissal is a setting that's available.
Unfortunately, it doesn't seem to work.
Here's my code:
.JMModal(
showModal: $appState.showPermissionsDialogue,
for: [.locationAlways, .calendar, .reminders, .health(categories: .init(read: HealthKitHelper.shared.permissionGroups.allTypes, write: HealthKitHelper.shared.permissionGroups.toWrite) )],
autoDismiss: true,
autoCheckAuthorization: true,
restrictDismissal: false,
onAppear: {},
onDisappear: {
EventsHelper.shared.getAuthorizationStatus()
}
)
An overview description of this task, along with a reference to the actual bug or feature issue like: tracking feature #72
.
Put all the instructional images, visuals, and prototypes here for reference.
Add special instructions, warnings, previous issues, and other related stuff here, if applicable.
An overview description of this task, along with a reference to the actual bug or feature issue like: tracking feature #72
.
Put all the instructional images, visuals, and prototypes here for reference.
Add special instructions, warnings, previous issues, and other related stuff here, if applicable.
I was getting the following error when trying to authorize HealthKit permissions:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Authorization to share the following types is disallowed: HKQuantityTypeIdentifierAppleExerciseTime, HKQuantityTypeIdentifierAppleStandTime'
I was pretty sure that I was initializing HKAccess with the correct permissions for read and write (aka toShare).
Digging into the code, In HMHealthPermissionManager.requestPermission, line 93 and 94 are as follows:
healthStore.requestAuthorization(toShare: Set(healthPermission?.readPermissions ?? []),
read: Set(healthPermission?.writePermissions ?? [])) { authorized, error in
"toShare" should be looking at the .writePermissions, not the readPermissions, so it should be:
healthStore.requestAuthorization(toShare: Set(healthPermission?.writePermissions ?? []),
read: Set(healthPermission?.readPermissions ?? [])) { authorized, error in
Btw: it would be good to add documentation on how to request health permissions in the README, I had to dig into the source code to figure it out :)
Suggestion from Redditor
Describe the bug
A clear and concise description of what the bug is.
PermissionSwiftUI 1.4.1
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Must request authorization for at least one data type'
To Reproduce
let readData = Set([HKObjectType.workoutType(),
HKObjectType.quantityType(forIdentifier: .stepCount)!,
HKObjectType.quantityType(forIdentifier: .distanceWalkingRunning)!,
HKObjectType.quantityType(forIdentifier: .activeEnergyBurned)!
,HKObjectType.quantityType(forIdentifier: .appleStandTime)!
])
.JMModal(showModal:$showPermission,for:[.locationAlways,.health(categories: .init(read: readData)),.notification])
Expected behavior
A clear and concise description of what you expected to happen.
in mapPermissionAuthorizationStatus
, input
is Set<HKSampleType>
, however I'm using HKObjectType
and it cause error
***Update:
Tried with HKSampleType
but still crash as I click to allow permission of Health.
*** update:
tried to downcast to PermissionSwiftUI 1.3.0, everything working fine!
Is your feature request related to a problem? Please describe.
It will be really helpful if there can be a closure to deliver back the results of the permission request. I might want to program certain actions to take place after the permission request, and I want to know what permissions are denied, and what permissions are allowed, along with any error in the process.
Describe the solution you'd like
Ideal closure would be integrated with the onDisappear
, pass back a structure of JMResult
which encapsulates each individual permission's authorization status, and error
if any error were to occur.
Describe alternatives you've considered
N/A
Additional context
Ideal implementation:
.JMAlert(showModal: $showModal,
for: [.camera, .locationAlways],
autoDismiss: true,
onAppear: {},
onDisappear: {(result: [JMResult], error: Error) in
guard error == nil else {print(error)}
if cameraAuth = result[0].authorizationStatus
})
}
Suggested by Gilles through email. Add the media player (Apple Music) permission into PermissionsSwiftUI's supported permissions. The media player permission is needed to play music through Apple Music.
Media Player Framework
Permission description
To contributors: please hold off on taking this issue for now. I am in progress of MAJOR refactoring that will change a lot of the code base. The refactoring should be finished by 3/25.
The JMModal
might be shown once at initial launch, and the JMAlert
should only show if permission is not granted. PermissionsSwiftUI will awkwardly show a pop-up every single time. There needs to be an automatic checking for permission granted status before built into PermissionsSwiftUI. Tracking #26
PermissionType
Put all the instructional images, visuals, and prototypes here for reference.
First, Apple's APIs for permission authorization status checking are asynchronous. It might introduce a delay to the PermissionsSwiftUI modal or alert.
✅ ❌ Be sure to write new unit tests, and ensure all unit tests pass.
Describe the bug
Here is the alert I get when trying to build:
The package product 'PermissionsSwiftUI' cannot be used as a dependency of this target because it uses unsafe build flags.
This happens when updating to versions 1.4.0 or 1.4.1.
Version 1.3.0 still builds.
To Reproduce
Steps to reproduce the behavior:
Just build & run
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context
Add any other context about the problem here.
Is your feature request related to a problem? Please describe.
The popup animation for JMAlert is not smooth and fluid like Apple's native alert, especially when closing it.
Describe the solution you'd like
Custom implementation of AnyTransition
.
Currently, the PermissionModel
enum includes tracking as an accessible enum case for all versions (13.0). However, the tracking permission is only available in iOS 14+, thus it does not make sense to show a tracking permission in targets below 14.0.
Need to figure out a way to conditionally include the tracking
enum case. The requestPermission
method also need to have a version check if the current enum case is tracking
.
Something like this:
Image credit: Varabeis's SPPermissions
Get coverage by Jazzy's JSON file
The default colour is blue for PermissionsSwiftUI, which doesn't quite work with my app's design.
For the permission images, I can pass in custom images and provide them with my preferred accent colour.
For the buttons, there seems to be no way to customize them. I see in the source code "ButtonStatusColor", but as it's not a public class I cannot extend it and over-ride it.
Being able to pass in an accent colour that when calling .JMModal would be great!
Describe the bug
A clear and concise description of what the bug is.
I'm using .JMModal on my login view and also in this view I have .sheet but .JMModal won't show when I have .sheet.
If I delete that lines of code, then .JMModal show perfectly.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context
Add any other context about the problem here.
A Redditor suggested that we provide a data model to be passed in to customize behaviors. When developers need to customize multiple, complex behaviors of PermissionsSwiftUI, they will have to write a stack of messy modifiers. However, a PermissionStore
model that can be extracted into a view model will allow more efficient and cleaner customization. Tracking #20.
Reference code snippet 1 and code snippet 2 for a direct comparison.
PermissionStore
as public. Extract the shared
and mutableShared
into a private extension, not accessible by API.JMPermission
's authorized property private, inaccessible from API.PermissionStore
that updates the entire model in shared
propertyCurrently, this is how you would customize PermissionsSwiftUI components:
.JMModal(showModal: $showModal,
for: [.health(healthPermissions),.calendar,
.bluetooth,.locationAlways, .microphone],
autoDismiss: true,
onAppear: {
},
onDisappear: {
})
.changeHeaderTo("New Header!")
.changeHeaderDescriptionTo("PermissionsSwiftUI is the best iOS library!")
.changeBottomDescriptionTo("PermissionsSwiftUI is the best iOS library!")
.setPermissionComponent(for: .health(healthPermissions), image: AnyView, title: String?, description: String?)
.setPermissionComponent(for: .calendar, image: AnyView, title: String?, description: String?)
.setPermissionComponent(for: .bluetooth, image: AnyView, title: String?, description: String?)
.setPermissionComponent(for: .locationAlways, image: AnyView, title: String?, description: String?)
.setPermissionComponent(for: .microphone, image: AnyView, title: String?, description: String?)
This is the ideal result, a data model that supplement the modifier method:
let model: PermissionStore = {
var model = PermissionStore()
model.permissions = [.camera, .health]
model.mainTexts.headerText = "Some title"
model.mainTexts.headerDescription = "Some description to be shown"
model.mainTexts.bottomDescription = "Some description to be shown"
model.healthPermission = JMPermission(imageIcon: AnyView(Image(systemName: "heart.fill")),
title: "Health",
description: "Allow to access your health information",
authorized: false)
return model
}
......
.JMModal(showModal: $showModal, forModel: model)
N/A
Describe the solution you'd like
A clear and concise description of what you want to happen.
I need to prevent user from dismissing modal view before allowing all permissions.
Currently, the one and only PermissionType
enum is used to designate a specific type of iOS system permission. However, the health permission require an associated value to be passed in, and lead to unnecessary complications when customizing the health component. Please see visual references section. No tracking issue.
currentPermission
so it can be extractedPermissionType
usage in custom modifiers with the new enumFor example, here I use a JMAlert popup with health and camera permission. I customize health permission with a title.
//Here the associated value is used to specify types of health permission.
.JMAlert(showModal: .constant(true),
for: [.health(([HKSampleType.quantityType(forIdentifier: .activeEnergyBurned)!])),
.camera])
//There is no point in passing in the entire HKSample type here again. Too much clutter.
.setPermissionComponent(for: .health([HKSampleType.quantityType(forIdentifier: .activeEnergyBurned)!]),
title: "My New Title")
Easy task here. I highly recommend you contribute, even if you barely have any experience with Swift or SwiftUI.
An overview description of this task, along with a reference to the actual bug or feature issue like: tracking feature #72
.
Put all the instructional images, visuals, and prototypes here for reference.
Add special instructions, warnings, previous issues, and other related stuff here, if applicable.
An overview description of this task, along with a reference to the actual bug or feature issue like: tracking feature #72
.
Put all the instructional images, visuals, and prototypes here for reference.
Add special instructions, warnings, previous issues, and other related stuff here, if applicable.
An overview description of this task, along with a reference to the actual bug or feature issue like: tracking feature #72
.
Put all the instructional images, visuals, and prototypes here for reference.
Add special instructions, warnings, previous issues, and other related stuff here, if applicable.
An overview description of this task, along with a reference to the actual bug or feature issue like: tracking feature #72
.
Put all the instructional images, visuals, and prototypes here for reference.
Add special instructions, warnings, previous issues, and other related stuff here, if applicable.
Is your feature request related to a problem? Please describe.
No.
Describe the solution you'd like
When developers are using the powerful feature of PermissionsSwiftUI in their iOS app, they might want to show the JMModal
only on first app launch. Or, they might only want to show the JMAlert
for camera permission right before user needs to use the camera. However, the alert and modal should not pop up, if permission is already granted.
Describe alternatives you've considered
Currently, without a built in auto permission authorization check, developers will have to implement their own authorization checking. That means importing all the related Apple modules, and interfacing with things like HealthKit
and EventKit
which defeats the purpose of PermissionsSwiftUI.
Additional context
This issue is tracked by #28
can you add cocoapods?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.