First, I code ATT authorization struct below which uses brand new Swift concurrency.
struct ATT {
private init() {}
static func permissionRequest() async -> Bool {
switch ATTrackingManager.trackingAuthorizationStatus {
case .notDetermined:
await ATTrackingManager.requestTrackingAuthorization()
return ATTrackingManager.trackingAuthorizationStatus == .authorized
case .restricted, .denied:
return false
case .authorized:
return true
@unknown default:
fatalError()
}
}
}
And Video authorization as well.
struct Video {
private init() {}
static func permissionRequest() async -> Bool {
switch AVCaptureDevice.authorizationStatus(for: .video) {
case .authorized:
return true
case .denied, .restricted:
return false
case .notDetermined:
await AVCaptureDevice.requestAccess(for: .video)
return AVCaptureDevice.authorizationStatus(for: .video) == .authorized
@unknown default:
fatalError()
}
}
}
Next, I request two permissions in serial, and works as I expected.
Remember uninstalling the app to reset those permissions status.
@IBAction func onClickButton(_ sender: Any?) {
Task {
_ = await ATT.permissionRequest() // okay
_ = await Video.permissionRequest() // okay
}
}
Lastly, I replace those order, and ATT alert is not showing this time.
That’s not what I expected.
Why ?
@IBAction func onClickButton(_ sender: Any?) {
Task {
_ = await Video.permissionRequest() // okay
_ = await ATT.permissionRequest() // not showing
}
}
And I noticed this would happen again when I called this from viewDidLoad()
override func viewDidLoad() {
super.viewDidLoad()
Task {
_ = await ATT.permissionRequest() // not showing
}
}
Seems like this behavior is since iOS 15 beta 3.