sparrowcode / PermissionsKit

Universal API for request permission and get its statuses.
https://x.com/sparrowcode_ios
MIT License
5.64k stars 462 forks source link

Add writeOnly type for calendar #320

Closed alexanderpuchta closed 1 year ago

alexanderpuchta commented 1 year ago

Goal

with iOS 17 there are two new methods to request access for calendars.

alexanderpuchta commented 1 year ago

closed because of #321

ivanvorobei commented 1 year ago

I think your solution cleaner. So we can move on with it

alexanderpuchta commented 1 year ago

i have updated the README file with help of #321 and added available iOS 17 only like suggested in https://github.com/sparrowcode/PermissionsKit/pull/321#discussion_r1338245557 @ivanvorobei

ivanvorobei commented 1 year ago
  1. Upgraded usage description key
open var usageDescriptionKey: String? {
        if #available(iOS 17, *) {
            switch kind {
            case .calendar(let access):
                switch access {
                case .full:
                    return "NSCalendarsFullAccessUsageDescription"
                case .write:
                    return "NSCalendarsWriteOnlyAccessUsageDescription"
                }
            default:
                fatalError()
            }
        } else {
            return "NSCalendarsUsageDescription"
        }
    }
  1. Updated permission access level to enum. For calendar it's CalendarAccess. As well

  2. drop @available(iOS 17.0, *) for calendar permission becouse no reason to have it. If dev asking write only it mean he want have full access on iOS 16.

  3. next merged 2 calendar permission to one calendar + access value

public extension Permission {

    static func calendar(access: CalendarAccess) -> CalendarPermission {
        CalendarPermission(kind: .calendar(access: access))
    }
}