Send App Usage Permission

App Usage Permission Alert to comply with the new App Store Guidelines

109
1
Swift

Send App Usage Permission

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.

Send App Usage Permission - Comply with the new App Store Guidelines | Product Hunt Embed

Installation

Just drag and drop it to your project.

Usage

Display Alert

Put this code in viewDidAppear

  override func viewDidAppear(_ animated: Bool) {
        if !AppUsagePermission.isAsked(){
            AppUsagePermission.displayAlert(viewController: self, completionHandler: nil)
        }

    }

сompletionHandler

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

Get permission statuses

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
}

Quck access functions

 if AppUsagePermission.isAsked(){
   print("Dalogue has been already presented to user")
 }
  if AppUsagePermission.isAllowed(){
    print("Send App Data Usage is allowed")
  }

Reset saved value

   AppUsagePermission.resetValue()

Credits

@kasabulatov

Join project on PH
Send App Usage Permission - Comply with the new App Store Guidelines | Product Hunt Embed

License

Fell free to use, share and modify