MIT License

项目介绍

sparrowcode/PermissionsKit 是一个托管在 GitHub 上的开源项目,主要使用 Swift 编写,采用 MIT License 许可证,目前获得 5.8k 个 Star、474 次 Fork。

仓库全名
sparrowcode/PermissionsKit
开源许可证
MIT License
Star 数
5.8k
Fork 数
474
未关闭 Issue
4

README 摘要

PermissionsKit Universal API for requesting permissions and reading their status — .authorized, .denied & .notDetermined. Each permission ships as a separate product, so the app compiles only the ones it actually uses. Installation In Xcode: File → Add Package Dependencies → paste URL: Then pick the products you need. Add only those — every permission API you link is visible to App Review, and unused ones invite…

完整内容见 GitHub 原始 README 或本页 。

常见问题

PermissionsKit 用什么语言开发?

主要使用 Swift 编写,采用 MIT License 许可证,目前有 5.8k 个 Star。

PermissionsKit 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 PermissionsKit 的源码?

可以直接克隆仓库:git clone https://github.com/sparrowcode/PermissionsKit.git,默认分支为 main;安装与运行步骤见仓库 README。

PermissionsKit 最近还在维护吗?

仓库最近一次更新为 9月12日,当前有 4 个未关闭 Issue;Star 数为 5.8k,可作为社区活跃度的参考。

README

PermissionsKit

Universal API for requesting permissions and reading their status — .authorized, .denied & .notDetermined. Each permission ships as a separate product, so the app compiles only the ones it actually uses.

Installation

In Xcode: File → Add Package Dependencies → paste URL:

https://github.com/sparrowcode/PermissionsKit

Then pick the products you need. Add only those — every permission API you link is visible to App Review, and unused ones invite questions about why the app needs them.

Permissions

Permission Product Key for Info.plist
Bluetooth BluetoothPermission NSBluetoothAlwaysUsageDescription, NSBluetoothPeripheralUsageDescription
Calendar CalendarPermission NSCalendarsUsageDescription, NSCalendarsFullAccessUsageDescription, NSCalendarsWriteOnlyAccessUsageDescription
Camera CameraPermission NSCameraUsageDescription
Contacts ContactsPermission NSContactsUsageDescription
FaceID FaceIDPermission NSFaceIDUsageDescription
Health HealthPermission NSHealthUpdateUsageDescription, NSHealthShareUsageDescription
Location LocationPermission NSLocationAlwaysAndWhenInUseUsageDescription, NSLocationWhenInUseUsageDescription
Media Library MediaLibraryPermission NSAppleMusicUsageDescription
Microphone MicrophonePermission NSMicrophoneUsageDescription
Motion MotionPermission NSMotionUsageDescription
Notification NotificationPermission —
Photo Library PhotoLibraryPermission NSPhotoLibraryUsageDescription, NSPhotoLibraryAddUsageDescription
Reminders RemindersPermission NSRemindersUsageDescription, NSRemindersFullAccessUsageDescription
Siri SiriPermission NSSiriUsageDescription
Speech Recognizer SpeechRecognizerPermission NSSpeechRecognitionUsageDescription
Tracking TrackingPermission NSUserTrackingUsageDescription

Usage

Request a permission:

import PermissionsKit
import NotificationPermission

Permission.notification([.alert, .badge, .sound]).request {
    // Called once the user answers the system dialog.
}

Read its status:

import PermissionsKit
import CameraPermission

let authorized = Permission.camera.authorized
Warning 警告

FaceID can’t tell .authorized from .notDetermined — both come back as .notDetermined. Only .denied is reliable.

Keys in Info.plist

Apple requires a usage description for most permissions. Get the key for a permission:

let key = Permission.bluetooth.usageDescriptionKey
Note 注意

Use the key itself, not the description text — Xcode won’t build otherwise.

Localisation

An xliff export creates the keys for you. Doing it by hand means adding an InfoPlist.strings file, selecting the languages in the inspector, and writing the keys there:

"NSCameraUsageDescription" = "Here description of usage camera";

评论

暂无评论