Reputation: 6606
I have an app which needs to be able to take photos (not videos). I was looking online to find out how to detect if the user has granted permission to the camera.
After a while I found that you could use AVAuthorizationStatus
to figure this out. However, on the Apple docs its says:
Calling this method with any media type other than AVMediaTypeVideo or AVMediaTypeAudio raises an exception.
So what if I want to take a photo then? How do I do that? There is no AVMediaTypePhoto
and I have not been able to find out how to authorise camera access in any other way.
This is the authorisation example code I found online, but I don't know if it will work if you just want to take pictures.
#import <AVFoundation/AVFoundation.h>
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if(status == AVAuthorizationStatusAuthorized) { // authorized
}
else if(status == AVAuthorizationStatusDenied){ // denied
}
else if(status == AVAuthorizationStatusRestricted){ // restricted
}
else if(status == AVAuthorizationStatusNotDetermined){ // not determined
[AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
if(granted){ // Access has been granted ..do something
} else { // Access denied ..do something
}
}];
}
Update 1
I was also looking into the PHPhotoLibrary
framework, but that only provides access to the photo library, not the camera.
Upvotes: 4
Views: 2924
Reputation: 1882
With iOS 9, You should enter your app name with key: "Bundle Display Name" in Info.plist.
Thanks to this https://stackoverflow.com/a/32880876/4628777
Change this
to this
Upvotes: 2
Reputation: 6606
Yes the code in my question does work, I was just being stupid and testing it on the iOS simulator and not on a real iDevice...... I think I need a coffee break :)
Upvotes: 1