interface.uts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * m-permission-manager 跨平台权限管理接口
  3. */
  4. /** 统一权限标识,三端通用 */
  5. export type PermissionKey =
  6. | 'camera'
  7. | 'photoLibrary'
  8. | 'storage'
  9. | 'readStorage'
  10. | 'location'
  11. | 'coarseLocation'
  12. | 'microphone'
  13. | 'contacts'
  14. | 'writeContacts'
  15. | 'bluetooth'
  16. | 'phone'
  17. | 'phoneState'
  18. | 'sms'
  19. | 'readSms'
  20. | 'receiveSms'
  21. | 'overlay'
  22. | 'writeSettings'
  23. export type PermissionStatus =
  24. | 'granted'
  25. | 'denied'
  26. | 'notDetermined'
  27. | 'restricted'
  28. | 'unsupported'
  29. export type PermissionCheckResult = {
  30. permission : PermissionKey
  31. status : PermissionStatus
  32. granted : boolean
  33. }
  34. export type PermissionGrantResult = {
  35. permission : PermissionKey
  36. status : PermissionStatus
  37. granted : boolean
  38. }
  39. export type CheckPermissionsResult = {
  40. results : PermissionCheckResult[]
  41. allGranted : boolean
  42. }
  43. export type RequestPermissionsResult = {
  44. results : PermissionGrantResult[]
  45. allGranted : boolean
  46. }
  47. export type CheckPermissionOptions = {
  48. permission : PermissionKey
  49. success ?: (res : PermissionCheckResult) => void
  50. fail ?: (res : PermissionFail) => void
  51. complete ?: (res : any) => void
  52. }
  53. export type CheckPermissionsOptions = {
  54. permissions : PermissionKey[]
  55. success ?: (res : CheckPermissionsResult) => void
  56. fail ?: (res : PermissionFail) => void
  57. complete ?: (res : any) => void
  58. }
  59. export type RequestPermissionOptions = {
  60. permission : PermissionKey
  61. success ?: (res : PermissionGrantResult) => void
  62. fail ?: (res : PermissionFail) => void
  63. complete ?: (res : any) => void
  64. }
  65. export type RequestPermissionsOptions = {
  66. permissions : PermissionKey[]
  67. success ?: (res : RequestPermissionsResult) => void
  68. fail ?: (res : PermissionFail) => void
  69. complete ?: (res : any) => void
  70. }
  71. export type OpenAppSettingsOptions = {
  72. /** 指定权限类型,各端将尽量跳转到对应设置页 */
  73. permission ?: PermissionKey
  74. success ?: (res : PermissionCheckResult) => void
  75. fail ?: (res : PermissionFail) => void
  76. complete ?: (res : any) => void
  77. }
  78. export type GetSupportedPermissionsResult = {
  79. permissions : PermissionKey[]
  80. }
  81. /**
  82. * 9020001 当前环境不支持
  83. * 9020002 用户拒绝授权
  84. * 9020003 权限不支持当前平台
  85. * 9020004 打开系统设置失败
  86. * 9020005 权限检查失败
  87. * 9020006 权限申请失败
  88. */
  89. export type PermissionErrorCode = 9020001 | 9020002 | 9020003 | 9020004 | 9020005 | 9020006
  90. export interface PermissionFail extends IUniError {
  91. errCode : PermissionErrorCode
  92. }
  93. export type CheckPermissionSync = (permission : PermissionKey) => PermissionCheckResult
  94. export type CheckPermissionsSync = (permissions : PermissionKey[]) => CheckPermissionsResult
  95. export type CheckPermission = (options : CheckPermissionOptions) => void
  96. export type CheckPermissions = (options : CheckPermissionsOptions) => void
  97. export type RequestPermission = (options : RequestPermissionOptions) => void
  98. export type RequestPermissions = (options : RequestPermissionsOptions) => void
  99. export type OpenAppSettings = (options : OpenAppSettingsOptions) => void
  100. export type GetSupportedPermissionsSync = () => GetSupportedPermissionsResult
  101. /** 蓝牙演示信息(读取系统蓝牙开关状态) */
  102. export type BluetoothDemoInfo = {
  103. available : boolean
  104. enabled : boolean
  105. stateText : string
  106. stateCode : number
  107. }
  108. export type GetBluetoothDemoInfoSync = () => BluetoothDemoInfo