App Usage Permission Alert to comply with the new App Store Guidelines
After WWDC 2019 Apple updated the App Store Guidelines
Guideline 5.1.1(i). Apps must get consent for data collection, even if the data is considered anonymous at the time of or immediately following collection.
(ii) Permission Apps that collect user or usage data must secure user consent for the collection, even if such data is considered to be anonymous at the time of or immediately following collection.
Inspired WWDC App I made class to help developers & community save time and comply with the App Store Guidelines.
Just drag and drop it to your project.
Put this code in viewDidAppear
override func viewDidAppear(_ animated: Bool) {
if !AppUsagePermission.isAsked(){
AppUsagePermission.displayAlert(viewController: self, completionHandler: nil)
}
}
AppUsagePermission.displayAlert(viewController: self, completionHandler: { result in
if (result == PermissionStatus.allowed){
print("User allowed data usage")
} else if (result == PermissionStatus.denied){
print("User denied data usage")
}
})
switch(AppUsagePermission.status()){
case .allowed:
print("Permission given")
case .denied:
print("Permission denied")
case .notAsked:
print("Data usage permission is not yet requested")
case .undefined:
print("Something went wrong")
}
enum PermissionStatus{
case allowed
case denied
case notAsked
case undefined
}
if AppUsagePermission.isAsked(){
print("Dalogue has been already presented to user")
}
if AppUsagePermission.isAllowed(){
print("Send App Data Usage is allowed")
}
AppUsagePermission.resetValue()
Fell free to use, share and modify