App Tracking Transparency on mac Silicon crash - ios

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?

Related

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.

Privacy settings for Photos authorizationStatus always returns notDetermined

Background
I am trying to determine the status of Privacy settings for saving to Photos with the below code, targeting iOS 10 through to iOS 14.
However in the Simulator, no matter what Privacy settings are selected for the app, the “authorizationStatus” returned is always “notDetermined”.
I would have expected the Privacy settings “Add Photos Only” to have returned “authorized”, and “None” to have returned “denied”.
Update
There seems to be an issue getting the Privacy status from
PHAccessLevel.addOnly, whereas getting the Privacy status from
PHAccessLevel.readWrite works correctly.
Privacy status always shows as "notDetermined" for this:
if #available(iOS 14, *) {
PHPhotoLibrary.requestAuthorization(for: PHAccessLevel.addOnly) { _ in
Privacy status shows expected result for this:
if #available(iOS 14, *) {
PHPhotoLibrary.requestAuthorization(for: PHAccessLevel.readWrite) { _ in
But I have no clue as to why that is the case...
Question
Is this a quirk with the iOS simulator, or is there an issue with my code, and if so, how do I correct it?
Code
import Photos
func authorizationStatusPhotos() {
if #available(iOS 14, *) {
PHPhotoLibrary.requestAuthorization(for: PHAccessLevel.addOnly) { _ in
switch PHPhotoLibrary.authorizationStatus() {
case .notDetermined:
print ("notDetermined")
case .restricted:
print ("restricted")
case .denied:
print ("denied")
case .authorized:
print ("authorized")
case .limited:
print ("limited")
default:
print ("default")
}
}
}
}
Image
For those, who's still looking for an answer: you should get the authorization status with the same PHAccessLevel with which you requested the Photos autorization, e.g.
PHPhotoLibrary.requestAuthorization(for: PHAccessLevel.addOnly)
...
PHPhotoLibrary.authorizationStatus(for: .addOnly)
PHPhotoLibrary.authorizationStatus() returns the status for read/write permission and is deprecated in iOS 15.

Swift - App Tracking Transparency - No Show Pop-Up due to ‘Allow Apps to Request to Track’ Greyed Out

As you now, Apple changed rules in mobile development in terms of Ads and tracking.
Apple prepared new Beta 14.5 iOS version. With this version tracking will be restricted. So, I wanted to simulate this option in my apps.
When I updated my phone to 14.5 iOS version(Beta) and Xcode(Version 12.5 beta 3 (12E5244e)), ‘Allow Apps to Request to Track’ option is greyed out, and can not changed.
So, in below code snipped, always return .restricted due to the above issue.
func requestPermission() {
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { status in
switch status {
case .authorized:
// Tracking authorization dialog was shown
// and we are authorized
print("Authorized")
// Now that we are authorized we can get the IDFA
print(ASIdentifierManager.shared().advertisingIdentifier)
case .denied:
// Tracking authorization dialog was
// shown and permission is denied
print("Denied")
case .notDetermined:
// Tracking authorization dialog has not been shown
print("Not Determined")
case .restricted:
print("Restricted")
#unknown default:
print("Unknown")
}
}
} else {
// Fallback on earlier versions
}
}
So, I am in stuck because of this issue. Do you have any option/suggession?
Not: In iOS 14.2 version everything was good, and ‘Allow Apps to Request to Track’ option could be changed. But now It's greyed out.
This worked for me
func requestIDFA() {
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization(completionHandler: { status in
// Tracking authorization completed. Start loading ads here.
})
} else {
// Fallback on earlier versions
}
}
}
IF you are using Appdelegate call it from ApplicationDidBecomeActive and if you are using Scenedelegate call it from SceneDidBecomeActive

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

xcode 8 & swift 3 - PHPhotoLibrary.requestAuthorization crashing

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

Resources