-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0adf53e
commit b4f3ebc
Showing
5 changed files
with
132 additions
and
12 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
Binary file added
BIN
+27.2 KB
...roj/project.xcworkspace/xcuserdata/rabeetahmad.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// | ||
// PermissionScreen.swift | ||
// Notes | ||
// | ||
// Created by Muhammad Khubaib Imtiaz on 01/01/2025. | ||
// | ||
|
||
import SwiftUI | ||
import AVFoundation | ||
|
||
struct PermissionScreen: View { | ||
|
||
@State var cameraPermission: AVAuthorizationStatus = AVCaptureDevice.authorizationStatus(for: .video) | ||
@State var cameraPermissionText: String = "Allow Camera" | ||
@State var photosPermissionText: String = "Allow Photos" | ||
@State var locationPermissionText: String = "Allow Location" | ||
|
||
@AppStorage("isPermissionGranted") private var isPermissionGranted = false | ||
|
||
var body: some View { | ||
VStack(alignment: .center, spacing: CGFloat(6)) { | ||
Image("notes") | ||
.resizable() | ||
.frame(width: 200, height: 200) | ||
.clipShape(RoundedRectangle(cornerRadius: 10)) | ||
|
||
Text("Please allow Notes to access your Camera, Photos, and Location.") | ||
.padding(.all) | ||
.frame(alignment: .center) | ||
|
||
|
||
|
||
Button { | ||
requestCameraPermission() | ||
if cameraPermission == .authorized { | ||
//isPermissionGranted = true | ||
cameraPermissionText = "Camera Permission Granted" | ||
} else { | ||
cameraPermissionText = "Allow Camera" | ||
} | ||
} label: { | ||
Label("\(cameraPermissionText)", systemImage: "camera") | ||
} | ||
|
||
Button { | ||
|
||
} label: { | ||
Label("Allow Photos", systemImage: "photo") | ||
} | ||
|
||
Button { | ||
|
||
} label: { | ||
Label("Allow Location", systemImage: "location") | ||
} | ||
}.onAppear { | ||
cameraPermission = AVCaptureDevice.authorizationStatus(for: .video) | ||
} | ||
} | ||
|
||
private func requestCameraPermission() { | ||
AVCaptureDevice.requestAccess(for: .video) { isGranted in | ||
DispatchQueue.main.async { | ||
cameraPermission = AVCaptureDevice.authorizationStatus(for: .video) | ||
} | ||
} | ||
} | ||
} |
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,41 @@ | ||
// | ||
// cameraPermissions.swift | ||
// Notes | ||
// | ||
// Created by Muhammad Khubaib Imtiaz on 01/01/2025. | ||
// | ||
|
||
import SwiftUI | ||
import AVFoundation | ||
|
||
|
||
struct CameraPermissions: View { | ||
|
||
@State private var cameraPermissionStatus: AVAuthorizationStatus = AVCaptureDevice.authorizationStatus(for: .video) | ||
|
||
|
||
|
||
var body: some View { | ||
VStack { | ||
if cameraPermissionStatus == .authorized { | ||
Text("Camera Permission Granted") | ||
}else{ | ||
Text("Camera Permissions Required") | ||
Button("Provide Camera Permissions", systemImage: "camera") { | ||
requestPermissions() | ||
} | ||
} | ||
|
||
}.onAppear { | ||
cameraPermissionStatus = AVCaptureDevice.authorizationStatus(for: .video) | ||
} | ||
} | ||
|
||
private func requestPermissions() { | ||
AVCaptureDevice.requestAccess(for: .video) { granted in | ||
DispatchQueue.main.async { | ||
cameraPermissionStatus = AVCaptureDevice.authorizationStatus(for: .video) | ||
} | ||
} | ||
} | ||
} |