4

I am using camera, microPhone and current location in my iOS App like SOS Button functionality. Its working fine but when I press this button first time its asking permissions for using these in-built features. How to ask permissions before using this SOS Button first time.

Ashley Mills
  • 50,474
  • 16
  • 129
  • 160
Gopal iOS
  • 97
  • 2
  • 7
  • 1
    [Requesting Authorization for Media Capture](https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/requesting_authorization_for_media_capture); [Swift Cheat Sheet for iPhone Camera Access & Usage](https://www.andrewcbancroft.com/2018/02/24/swift-cheat-sheet-for-iphone-camera-access-usage/); [AVAudioSession Swift](https://stackoverflow.com/questions/24318791/avaudiosession-swift) – MadProgrammer Aug 20 '18 at 04:54

1 Answers1

2

you can check in app delegate when app is launch so your permission is granted.

let mediatype = AVMediaType.video
let AuthoriseStatus = AVCaptureDevice.authorizationStatus(for: cameraMediaType)

switch AuthoriseStatus {
case .denied: break
case .authorized: break
case .restricted: break

case .notDetermined:
    // permission prompt
    AVCaptureDevice.requestAccess(for: mediatype) { granted in
        if granted {
            print("Granted access to \(mediatype)")
        } else {
            print("Denied access to \(mediatype)")
        }
    }
}
ikbal
  • 1,114
  • 1
  • 11
  • 30