permission
import "github.com/tangoui/tango/sys/permission"本页由
site/tools/apigen从源码注释生成(按 darwin 构建标签选文件),请勿手改。
Package permission queries and requests runtime permissions with one API on iOS and Android.
st, err := permission.Check(a, permission.Camera)
if st == permission.NotDetermined {
st, err = permission.Request(a, permission.Camera)
}
Statuses: Granted, Denied (refused, restricted by policy, or "don't ask again" on Android), Limited (selected photos only, approximate location, provisional notifications) and NotDetermined (never asked: Request will prompt). Request does not prompt again once the user decided; send the user to the system settings instead.
The app must declare what it asks for — an Info.plist usage description on iOS (Request returns ErrNotConfigured instead of crashing without it), a manifest permission on Android. See docs/mobile-permissions.md; tan generates them from "permissions" in tan.json.
Functions return ErrUnsupported where the backend has no runtime permissions (desktop) or does not know the permission, and tango.ErrNotRunning after the app quit. On Android call Request from a goroutine, not from a main-thread callback.
常量
const (
Camera = platform.PermCamera
Photos = platform.PermPhotos
Location = platform.PermLocation // while the app is in use
LocationAlways = platform.PermLocationAlways // also in the background
Notifications = platform.PermNotifications
Microphone = platform.PermMicrophone
)const (
Granted = platform.StatusGranted
Denied = platform.StatusDenied
Limited = platform.StatusLimited
NotDetermined = platform.StatusNotDetermined
)变量
var (
ErrUnsupported = platform.ErrUnsupported
ErrNotConfigured = platform.ErrNotConfigured
)var All = []Kind{Camera, Photos, Location, LocationAlways, Notifications, Microphone}All lists every Kind.
类型
Kind
type Kind = platform.PermissionKind names a permission (the same names as tan.json "permissions").
Status
type Status = platform.PermissionStatusStatus of a permission: "granted", "denied", "limited", "notDetermined".
func Check
func Check(a *tango.App, k Kind) (Status, error)Check returns the current status without prompting.
func Request
func Request(a *tango.App, k Kind) (Status, error)Request prompts the user if they were never asked and returns the resulting status.