Created
September 9, 2016 20:46
-
-
Save roblav96/fe7090f6ebbed56fd116fdc8f4451678 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
import {Injectable} from "@angular/core" | |
import {confirm} from "ui/dialogs" | |
@Injectable() | |
export class Permissions { | |
private addressBook: any = null | |
isContactsAuthorized(): boolean { | |
return ABAddressBookGetAuthorizationStatus() == ABAuthorizationStatus.kABAuthorizationStatusAuthorized | |
} | |
isContactsDenied(): boolean { | |
let status: any = ABAddressBookGetAuthorizationStatus() | |
let denied: boolean = ( | |
status == ABAuthorizationStatus.kABAuthorizationStatusDenied | |
|| | |
status == ABAuthorizationStatus.kABAuthorizationStatusRestricted | |
) | |
return denied | |
} | |
requestContactsAuthorization(): Promise<boolean> { | |
let status: any = ABAddressBookGetAuthorizationStatus() | |
if (status == ABAuthorizationStatus.kABAuthorizationStatusAuthorized) { | |
return Promise.resolve(true) | |
} else { | |
if (!this.addressBook) { | |
this.addressBook = ABAddressBookCreateWithOptions(null, null) | |
} | |
return new Promise((resolve) => { | |
ABAddressBookRequestAccessWithCompletion(this.addressBook, function(status: boolean, error: NSError): void { | |
if (error) { | |
resolve(false) | |
} else { | |
resolve(status) | |
} | |
}) | |
}) | |
} | |
} | |
isPhotosAuthorized(): boolean { | |
return PHPhotoLibrary.authorizationStatus() == PHAuthorizationStatus.PHAuthorizationStatusAuthorized | |
} | |
isPhotosDenied(): boolean { | |
let status: any = PHPhotoLibrary.authorizationStatus() | |
let denied: boolean = ( | |
status == PHAuthorizationStatus.PHAuthorizationStatusDenied | |
|| | |
status == PHAuthorizationStatus.PHAuthorizationStatusRestricted | |
) | |
return denied | |
} | |
requestPhotosAuthorization(): Promise<boolean> { | |
return new Promise(function(resolve) { | |
PHPhotoLibrary.requestAuthorization(function(status: number): void { | |
let authed: boolean = (status == PHAuthorizationStatus.PHAuthorizationStatusAuthorized) | |
resolve(authed) | |
}) | |
}) | |
} | |
isSMSAuthorized(): boolean { | |
return true | |
} | |
isSMSDenied(): boolean { | |
return false | |
} | |
requestSMSAuthorization(): Promise<boolean> { | |
return Promise.resolve(true) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment