index.d.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * m-permission-manager UTS 插件 TypeScript 类型声明
  3. */
  4. export type PermissionKey =
  5. | 'camera'
  6. | 'photoLibrary'
  7. | 'storage'
  8. | 'readStorage'
  9. | 'location'
  10. | 'coarseLocation'
  11. | 'microphone'
  12. | 'contacts'
  13. | 'writeContacts'
  14. | 'bluetooth'
  15. | 'phone'
  16. | 'phoneState'
  17. | 'sms'
  18. | 'readSms'
  19. | 'receiveSms'
  20. | 'overlay'
  21. | 'writeSettings'
  22. export type PermissionStatus =
  23. | 'granted'
  24. | 'denied'
  25. | 'notDetermined'
  26. | 'restricted'
  27. | 'unsupported'
  28. export interface PermissionCheckResult {
  29. permission: PermissionKey
  30. status: PermissionStatus
  31. granted: boolean
  32. }
  33. export interface PermissionGrantResult {
  34. permission: PermissionKey
  35. status: PermissionStatus
  36. granted: boolean
  37. }
  38. export interface CheckPermissionsResult {
  39. results: PermissionCheckResult[]
  40. allGranted: boolean
  41. }
  42. export interface RequestPermissionsResult {
  43. results: PermissionGrantResult[]
  44. allGranted: boolean
  45. }
  46. export interface PermissionFail {
  47. errCode: 9020001 | 9020002 | 9020003 | 9020004 | 9020005 | 9020006
  48. errMsg: string
  49. }
  50. export interface CheckPermissionOptions {
  51. permission: PermissionKey
  52. success?: (res: PermissionCheckResult) => void
  53. fail?: (res: PermissionFail) => void
  54. complete?: (res: unknown) => void
  55. }
  56. export interface CheckPermissionsOptions {
  57. permissions: PermissionKey[]
  58. success?: (res: CheckPermissionsResult) => void
  59. fail?: (res: PermissionFail) => void
  60. complete?: (res: unknown) => void
  61. }
  62. export interface RequestPermissionOptions {
  63. permission: PermissionKey
  64. success?: (res: PermissionGrantResult) => void
  65. fail?: (res: PermissionFail) => void
  66. complete?: (res: unknown) => void
  67. }
  68. export interface RequestPermissionsOptions {
  69. permissions: PermissionKey[]
  70. success?: (res: RequestPermissionsResult) => void
  71. fail?: (res: PermissionFail) => void
  72. complete?: (res: unknown) => void
  73. }
  74. export interface OpenAppSettingsOptions {
  75. /** 指定权限类型,各端将尽量跳转到对应设置页 */
  76. permission?: PermissionKey
  77. success?: (res: PermissionCheckResult) => void
  78. fail?: (res: PermissionFail) => void
  79. complete?: (res: unknown) => void
  80. }
  81. export interface GetSupportedPermissionsResult {
  82. permissions: PermissionKey[]
  83. }
  84. export interface BluetoothDemoInfo {
  85. available: boolean
  86. enabled: boolean
  87. stateText: string
  88. stateCode: number
  89. }
  90. export function checkPermissionSync(permission: PermissionKey): PermissionCheckResult
  91. export function checkPermissionsSync(permissions: PermissionKey[]): CheckPermissionsResult
  92. export function checkPermission(options: CheckPermissionOptions): void
  93. export function checkPermissions(options: CheckPermissionsOptions): void
  94. export function requestPermission(options: RequestPermissionOptions): void
  95. export function requestPermissions(options: RequestPermissionsOptions): void
  96. export function openAppSettings(options?: OpenAppSettingsOptions): void
  97. export function getSupportedPermissionsSync(): GetSupportedPermissionsResult
  98. export function getBluetoothDemoInfoSync(): BluetoothDemoInfo