Skip to content

permission ​

go
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.

常量 ​

go
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
)
go
const (
	Granted       = platform.StatusGranted
	Denied        = platform.StatusDenied
	Limited       = platform.StatusLimited
	NotDetermined = platform.StatusNotDetermined
)

变量 ​

go
var (
	ErrUnsupported   = platform.ErrUnsupported
	ErrNotConfigured = platform.ErrNotConfigured
)
go
var All = []Kind{Camera, Photos, Location, LocationAlways, Notifications, Microphone}

All lists every Kind.

类型 ​

Kind ​

go
type Kind = platform.Permission

Kind names a permission (the same names as tan.json "permissions").

Status ​

go
type Status = platform.PermissionStatus

Status of a permission: "granted", "denied", "limited", "notDetermined".

func Check ​

go
func Check(a *tango.App, k Kind) (Status, error)

Check returns the current status without prompting.

func Request ​

go
func Request(a *tango.App, k Kind) (Status, error)

Request prompts the user if they were never asked and returns the resulting status.

以 MIT 许可发布