xcode 8 & swift 3 - PHPhotoLibrary.requestAuthorization crashing - ios

I have upgraded my project to swift 3 and working with Xcode 8
Now when I want to access the photos I get a crash, with no information in the console.
I have added "Privacy - Photo Library Usage Description" to my info.plist.
Please see images below for more information.
Thanks
Reza

There appeared to be multiple .plists in my project and by mistake I had edited the wrong .plist

Proper way to do is
let status = PHPhotoLibrary.authorizationStatus()
switch status {
case .authorized:
case .denied, .restricted :
//handle denied status
case .notDetermined:
// ask for permissions
PHPhotoLibrary.requestAuthorization() { (status) -> Void in
switch status {
case .authorized:
// as above
case .denied, .restricted:
// as above
case .notDetermined: break
// won't happen but still
}
}
}

Related

App Tracking Transparency on mac Silicon crash

I have iOS application (that works properly on iOS) and it has enabled destination: Mac(Designed for iPad). When run it on mac M1, the dialog doesnt appear and the code that it used to ask permissions for tracking always returns ATTrackingManager.AuthorizationStatus.notDetermined
The code it here:
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { [weak self] status in
switch status {
case .authorized:
DispatchQueue.main.async {
self?.didTrackingAuthorized?()
}
// Tracking authorization dialog was shown
// and we are authorized
case .denied:
// Tracking authorization dialog was
// shown and permission is denied
print("FB - Denied")
case .notDetermined:
self?.setup()
print("FB - Not Determined")
case .restricted:
print("FB - Restricted")
#unknown default:
print("FB - Unknown")
}
}
}
In documentation I read the Note about such behaviour:
If you call ATTrackingManager.trackingAuthorizationStatus in macOS, ATTrackingManager.AuthorizationStatus.notDetermined returns.
So the question is how in this case properly ask user permission for tracking activity on macos?

ATTrackingManager.requestTrackingAuthorization always returns "Not Determined" and prompt is never shown

I have read all exisiting posts about this topic, but until now I can not get it to work.
Somehow calling ATTrackingManager.requestTrackingAuthorization never shows the popup.
I added Privacy - Tracking Usage Description to the info list. I also turned on the system permissions.
I am developing the app with SwiftUI. Target device runs ios 15.4.
Any ideas what else to try? Maybe this is related to swiftUI?
Code:
DeckListView(decks: $store.decks){
Task {
....
}
}
}.onAppear{
requestPermission()
}
func requestPermission() {
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { status in
switch status {
case .authorized:
print("Authorized")
print(ASIdentifierManager.shared().advertisingIdentifier)
case .denied:
print("Denied")
case .notDetermined:
// Tracking authorization dialog has not been shown
// always the case for me
print("Not Determined")
case .restricted:
print("Restricted")
#unknown default:
print("Unknown")
}
}
}
}
}
Finally I found the source of my problem.
I accidentally called ATTrackingManager.requestTrackingAuthorization twice.
The first time I called while the app was not in an active state. It seems if the first call is made outside active state, any other calls will no longer show the popup.

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

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

how to get Permissions for photos access in iOS 9 with photos framework

I want to get photos through photos framework in iOS9 with Swift 2.photos framework is not allowed to access images and not asking permissions for access.
Simply add Photos framework in "Link Binary With Libraries" under build phases,Then import framework in class where its required.
To access photos permissions you need to give "Bundle display name" in plist file
and use following code
PHPhotoLibrary.requestAuthorization { (status) -> Void in
switch status{
case .Authorized:
dispatch_async(dispatch_get_main_queue(), {
print("Authorized")
})
break
case .Denied:
dispatch_async(dispatch_get_main_queue(), {
print("Denied")
})
break
default:
dispatch_async(dispatch_get_main_queue(), {
print("Default")
})
break
}
}

Resources