mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 11:08:06 +00:00
Add push notification permission request
This commit is contained in:
parent
fd61bca29f
commit
3461b096eb
1 changed files with 26 additions and 10 deletions
|
|
@ -20,25 +20,41 @@
|
|||
import Foundation
|
||||
import Photos
|
||||
import Contacts
|
||||
import UserNotifications
|
||||
import SwiftUI
|
||||
|
||||
class PermissionManager: ObservableObject {
|
||||
|
||||
static let shared = PermissionManager()
|
||||
|
||||
@Published var pushPermissionGranted = false
|
||||
@Published var photoLibraryPermissionGranted = false
|
||||
@Published var cameraPermissionGranted = false
|
||||
@Published var contactsPermissionGranted = false
|
||||
@Published var contactsPermissionGranted = false
|
||||
@Published var microphonePermissionGranted = false
|
||||
|
||||
private init() {}
|
||||
|
||||
func getPermissions() {
|
||||
pushNotificationRequestPermission()
|
||||
microphoneRequestPermission()
|
||||
photoLibraryRequestPermission()
|
||||
cameraRequestPermission()
|
||||
contactsRequestPermission()
|
||||
}
|
||||
|
||||
func pushNotificationRequestPermission() {
|
||||
let options: UNAuthorizationOptions = [.alert, .sound, .badge]
|
||||
UNUserNotificationCenter.current().requestAuthorization(options: options) { (granted, error) in
|
||||
if let error = error {
|
||||
Log.error("Unexpected error when asking for Push permission : \(error.localizedDescription)")
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
self.pushPermissionGranted = granted
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func microphoneRequestPermission() {
|
||||
AVAudioSession.sharedInstance().requestRecordPermission({ granted in
|
||||
DispatchQueue.main.async {
|
||||
|
|
@ -62,13 +78,13 @@ class PermissionManager: ObservableObject {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
func contactsRequestPermission() {
|
||||
let store = CNContactStore()
|
||||
store.requestAccess(for: .contacts) { success, _ in
|
||||
DispatchQueue.main.async {
|
||||
self.contactsPermissionGranted = success
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func contactsRequestPermission() {
|
||||
let store = CNContactStore()
|
||||
store.requestAccess(for: .contacts) { success, _ in
|
||||
DispatchQueue.main.async {
|
||||
self.contactsPermissionGranted = success
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue