UIImagePickerController in iOS 14+ with Limited Access - ios

I have an App which needs to Access Photos and Videos from the iPhone Photos App. in iOS 14+ Apple has Introduced new API PHPicker but that still lacks lot of common feature like Cropping image, trimming video.
Issue comes, When you have limited Access instead of Access to all photos, How to handle this?
let authorizationStatus = PHPhotoLibrary.authorizationStatus(for: .readWrite)
switch authorizationStatus {
case .limited:
print("limited authorization granted")
// ?????? -> Display UIImagePicker doesn't behave properly
case .authorized:
print("authorization granted")
self.accessLibrary()
case .notDetermined:
print("Status not determined")
PHPhotoLibrary.requestAuthorization(for: .readWrite) { status in
self.checkPhotoAccess()
}
default:
print("Implement this")
break
}
Do we need to create an intermediate screen fetch all the PHAsset and let user select among those first (Photos for which access is given)?
OR there's another way?
Please suggest

Related

How do you redirect user to settings after denying permissions for Save Image from UIActivityController?

After a user takes a photo in my app, there is a UIUserActivity that is presented that allows users to save and image. A pop up comes up and asks for permission to write the photo to the users photo album. However, if the user denies there is no way to prompt the user to be redirected to the photo library. PHPhoto authorization status is always returning undetermined even though permissions were already asked for. I am looking for a few things to be satisfied:
the user should be able to deny but continue to be prompted to give permission to the app if they want to save their photo.
if the user denies, I want the option of "save photo" to remain in the UIUserActivity as a potential option
How can I accomplish this?
I've tried using the PHPhotoLibrary authorization status, but it always returns undetermined. I've tried checking for .undetermined and using the PHPhotoLibrary to request access to the user's camera roll, however if the user denies at this point then the option to save photo is completely removed from the UIUserActivity pop up.
code:
activityViewController.completionWithItemsHandler = { activity, success, items, error in
if success {
if let activity = activity {
...
case .saveToCameraRoll:
handleCameraRollPermission()
func handleCameraRollPermission(status: PHAuthorizationStatus? = nil, completion: #escaping ((Bool) -> Void)) {
let authorizationStatus = status ?? PHPhotoLibrary.authorizationStatus()
switch authorizationStatus {
case .denied, .restricted:
showPermissionMissingAlert(completion: completion)
case .notDetermined:
PHPhotoLibrary.requestAuthorization { (status) in
switch(status) {
case .denied, .restricted, .notDetermined:
self.showPermissionMissingAlert(completion: completion)
default:
break
}
}
default:
completion(true)
}
}
This might be a bit overdoing it, but you could create a custom action section for the activityView. You can find more about that here and scroll down to the Adding a custom action section.
Basically you would make a custom save button that would persist regardless of permission status. When it is tapped you can check their authorization status and go from there.

Photo Library and Camera are accessible after permission got denied

I'm currently working on an app where I need to access either the photo library or the camera (or even both, it's up to the user).
If I close the app and deny the access to both camera and library for the app.
After restarting my App, it's still possible to access both, I can open and use the camera or even pick a photo from the library.
How is this possible, I thought Apple would restrict the access.
I dont think so. Apple always restrict use of camera or photo library if access is denied. Please use following code to check current status and verify it.
import Photos
if type == .CAMERA{
if AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo) == AVAuthorizationStatus.authorized {
completionHander(true) //Allowed
} else {
//Dont Know
AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { (granted: Bool) -> Void in
completionHander(granted)
})
}
}else{
let status = PHPhotoLibrary.authorizationStatus()
switch status {
case .authorized:
completionHander(true)//Allowed
break
case .denied, .restricted :
completionHander(false)//Not Allowed
break
case .notDetermined:
//Dont Know
PHPhotoLibrary.requestAuthorization { status in
switch status {
case .authorized:
completionHander(true)
break
case .denied, .restricted:
completionHander(false)
break
case .notDetermined:
completionHander(false)
break
}
}
}
}
Okay I know the answer...
I just didn't get the concept.
If I deny the access to the photoLibrary it is not possible to save images but, if Camera access is granted I can still use the photoLibrary.
If camera access is denied, I still get the alert with the context from the info.plist

Not showing alert even when I add Camera Usage Description / Photo Library Usage Description

I have camera/ photo library in my app, so I add request permission in plist. However, after running app, it does not even pop up alert. Just access to pick photo / camera. Is there anything I miss to add?
Thanks!
Requesting Authorization for Media Capture on iOS:
https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/requesting_authorization_for_media_capture_on_ios
Configure Your App's Info.plist File:
If your app uses device cameras, include the 'NSCameraUsageDescription' key in your app’s Info.plist file.
Verify and Request Authorization for Capture:
override func viewDidLoad() {
super.viewDidLoad()
switch AVCaptureDevice.authorizationStatus(for: .video) {
case .authorized: // The user has previously granted access to the camera.
.....
case .notDetermined: // The user has not yet been asked for camera access.
AVCaptureDevice.requestAccess(for: .video) { granted in
if granted {
.....
}
}
case .denied: // The user has previously denied access.
return
case .restricted: // The user can't grant access due to restrictions.
return
}
}

Ask Permissions before use in-built features in iOS

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.
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)")
}
}
}

Requesting music library permissions swift or obj-c

I want to request music library permissions right when my application opens the first time.
The privacy in my info.plist are:
Privacy - Media library usage description
and
Privacy - music usage description
I would prefer this to be in my app delegate did finish launching with options but it is okay if it is in my viewDidLoad of the first viewController of my app.
You can request for permission like
let status = MPMediaLibrary.authorizationStatus()
switch status {
case .authorized:
// Get Media
case .notDetermined:
MPMediaLibrary.requestAuthorization() { status in
if status == .authorized {
DispatchQueue.main.async {
// // Get Media
}
}
}
}

Resources