-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from QuickBlox/Release-0.1.5
Release QuickBlox UIKit 0.1.5
- Loading branch information
Showing
68 changed files
with
2,308 additions
and
580 deletions.
There are no files selected for viewing
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
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
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
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
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
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
38 changes: 38 additions & 0 deletions
38
Sources/QuickBloxData/Repository/PermissionsRepository.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// PermissionsRepository.swift | ||
// QuickBloxUIKit | ||
// | ||
// Created by Injoit on 25.08.2023. | ||
// Copyright © 2023 QuickBlox. All rights reserved. | ||
// | ||
|
||
import QuickBloxDomain | ||
import AVFoundation | ||
|
||
public class PermissionsRepository { | ||
private var repo: PermissionsRepositoryProtocol! | ||
|
||
init(repo: PermissionsRepositoryProtocol) { | ||
self.repo = repo | ||
} | ||
|
||
private init() { } | ||
} | ||
|
||
extension PermissionsRepository: PermissionsRepositoryProtocol { | ||
public func openSettings() async throws { | ||
do { | ||
try await repo.openSettings() | ||
} catch { | ||
throw try error.repositoryException | ||
} | ||
} | ||
|
||
public func get(permissionTo mediaType: AVMediaType) async throws -> Bool { | ||
do { | ||
return try await repo.get(permissionTo: mediaType) | ||
} catch { | ||
throw try error.repositoryException | ||
} | ||
} | ||
} |
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
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
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
57 changes: 57 additions & 0 deletions
57
Sources/QuickBloxData/Source/Local/PermissionsSource.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// PermissionsSource.swift | ||
// QuickBloxUIKit | ||
// | ||
// Created by Injoit on 25.08.2023. | ||
// Copyright © 2023 QuickBlox. All rights reserved. | ||
// | ||
|
||
import QuickBloxDomain | ||
import AVFoundation | ||
import UIKit | ||
|
||
class PermissionsSource { | ||
|
||
} | ||
|
||
//MARK: PermissionsRepositoryProtocol | ||
extension PermissionsSource: PermissionsRepositoryProtocol { | ||
func openSettings() async throws { | ||
if let url = await URL(string: UIApplication.openSettingsURLString) { | ||
await UIApplication.shared.open(url, options: [:]) | ||
} | ||
} | ||
|
||
func get(permissionTo mediaType: AVMediaType) async throws -> Bool { | ||
switch mediaType { | ||
case .audio: return try await PermissionsSource.requestPermissionTo(.audio) | ||
case .video: return try await PermissionsSource.requestPermissionTo(.video) | ||
default: return false | ||
} | ||
} | ||
} | ||
|
||
private extension PermissionsSource { | ||
|
||
static func requestPermissionTo(_ mediaType: AVMediaType) async throws -> Bool { | ||
switch mediaType { | ||
case .audio: | ||
return try await withCheckedThrowingContinuation { continuation in | ||
AVAudioSession.sharedInstance().requestRecordPermission({ granted in | ||
DispatchQueue.main.async(execute: { | ||
continuation.resume(returning: granted) | ||
}) | ||
}) | ||
} | ||
case .video: | ||
return try await withCheckedThrowingContinuation { continuation in | ||
AVCaptureDevice.requestAccess(for: .video, completionHandler: {granted in | ||
DispatchQueue.main.async { | ||
continuation.resume(returning: granted) | ||
} | ||
}) | ||
} | ||
default: return false | ||
} | ||
} | ||
} |
Oops, something went wrong.