Closed sido420 closed 4 years ago
Here https://github.com/NathanaelA/nativescript-permissions/issues/12, its been claimed that (as of Aug 2016) those are the only iOS permissions.
Can we get inspiration from @roblav96's code?
@sido420 I found this in an old project, might help get you started.
permissions.extension.ios.ts
import { Application, Device } from '@nativescript/core'
const _contactStore: CNContactStore = CNContactStore.alloc().init()
function _getContactsAuthorization(): CNAuthorizationStatus {
return CNContactStore.authorizationStatusForEntityType(CNEntityType.Contacts)
}
export function isContactsAuthorized(): boolean {
return _getContactsAuthorization() == CNAuthorizationStatus.Authorized
}
export function isContactsDenied(): boolean {
let status: CNAuthorizationStatus = _getContactsAuthorization()
let denied: boolean =
status == CNAuthorizationStatus.Denied || status == CNAuthorizationStatus.Restricted
return denied
}
export function requestContactsAuthorization(): Promise<boolean> {
if (_getContactsAuthorization() == CNAuthorizationStatus.Authorized) {
return Promise.resolve(true)
} else {
return new Promise((resolve) => {
_contactStore.requestAccessForEntityTypeCompletionHandler(
CNEntityType.Contacts,
function completionHandler(result: boolean, error: NSError): void {
if (error) {
console.error('requestAccessForEntityTypeCompletionHandler > error', error)
resolve(false)
} else {
resolve(result)
}
},
)
})
}
}
export function isPhotosAuthorized(): boolean {
return PHPhotoLibrary.authorizationStatus() == PHAuthorizationStatus.Authorized
}
export function isPhotosDenied(): boolean {
let status: PHAuthorizationStatus = PHPhotoLibrary.authorizationStatus()
let denied: boolean =
status == PHAuthorizationStatus.Denied || status == PHAuthorizationStatus.Restricted
return denied
}
export function requestPhotosAuthorization(): Promise<boolean> {
return new Promise(function (resolve) {
PHPhotoLibrary.requestAuthorization(function (status: number): void {
let authed: boolean = status == PHAuthorizationStatus.Authorized
resolve(authed)
})
})
}
export function isNotificationsAuthorized(): boolean {
let nativeApp: UIApplication = Application.ios.nativeApp
let version = parseFloat(Device.osVersion)
if (version >= 8) {
let enabled = nativeApp.registeredForRemoteNotifications
let types = nativeApp.currentUserNotificationSettings.types
return enabled && types != UIUserNotificationType.None
}
let types = nativeApp.enabledRemoteNotificationTypes()
return types != UIRemoteNotificationType.None
}
Will look at it. Also this plugin is a direct port of the react native one. Need to see if they added since then.
@sido420 are we talking about ios13 external storage permissions? Do you have example native code?
Thanks for looking into it.
I was referring to iOS external storage in general. From the chart in this module, it appears storage permission for iOS is not supported, hence I wanted to request adding support for that. I don't know version differences in iOS and not sure if permission is even required for iOS.
I'm afraid, I don't have native code available, since I am still learning NS development. However, there is some discussion on storage at https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/index.html#ios-quirks.
@sido420 ok. So i dont think it is needed , thus the graph here.
Just to clarify: Everything in https://github.com/nativescript-community/nativescript-perms#supported-permissions-types that has cross with it means it does not require a permission by the platform. Please confirm.
Yes that s it. And you can "request" permission still. It will return "true" if not needed by the platform
How difficult is it to add storage permission support on iOS?
I have never done native app development but can try.