sparrowcode / PermissionsKit

Universal API for request permission and get its statuses.
https://x.com/sparrowcode_ios
MIT License
5.64k stars 462 forks source link

Cant get dialog to segue after receiving permission #21

Closed SirSamShaw closed 7 years ago

SirSamShaw commented 7 years ago

I am using the isAllowed as documented and when checking if all permissions are granted, it will not print it out let alone segue.. can I have a code sample of checking for a permission and segueing on didHide()

ivanvorobei commented 7 years ago

@SirSamShaw Hi! You can send me example project? My English is bad and I don't understand that troubles with project

mgt-la commented 7 years ago

@SirSamShaw didHide means they did not tap to take action on a permission request. But this is how I handle things so that they are not shown the permission request if they've already given permission.

class ViewController: UIViewController, SPRequestPermissionEventsDelegate {

  @IBAction func btn1(_ sender: Any) {
      if SPRequestPermission.isAllowPermission(.locationWhenInUse) {
          self.desiredAction()
      } else {
          SPRequestPermission.dialog.interactive.present(on: self, with: [.locationWhenInUse])
      }
  }

  func didAllowPermission(permission: SPRequestPermissionType) {
      if permission == .locationWhenInUse {
          self.desiredAction()
      }
  }

  func desiredAction() {
      //whatever you want to happen now
  }

  func didDeniedPermission(permission: SPRequestPermissionType) {
      //required?
  }

  func didSelectedPermission(permission: SPRequestPermissionType) {
      //required?
  }

  func didHide() {
      //required?
  } 
}  
jonajgs commented 6 years ago

Hi @mgt-la

In my code, dont entry to the protocol SPRequestPermissionEventsDelegate

class ConfigurationViewController: FormViewController, SPRequestPermissionEventsDelegate {
    // ....   

     func didHide() {
        print("didHide")

    }

    func didAllowPermission(permission: SPRequestPermissionType) {
        print("didAllowPermission")

    }

    func didDeniedPermission(permission: SPRequestPermissionType) {
        print("didDeniedPermission")

    }

    func didSelectedPermission(permission: SPRequestPermissionType) {
        print("didSelectedPermission")

    }
}

Any ideas ?

ivanvorobei commented 6 years ago

@jonajgs you set delegate? show code

jonajgs commented 6 years ago

@IvanVorobei

the code is above, i only miss the viewDidLoad

class ConfigurationViewController: FormViewController, SPRequestPermissionEventsDelegate {
    override func viewDidLoad() {
        super.viewDidLoad()

        GIDSignIn.sharedInstance().delegate = self
        GIDSignIn.sharedInstance().uiDelegate = self

        buildForm()
    }

     func buildForm() {

    }

    func didHide() {
        print("didHide")

    }

    func didAllowPermission(permission: SPRequestPermissionType) {
        print("didAllowPermission")

    }

    func didDeniedPermission(permission: SPRequestPermissionType) {
        print("didDeniedPermission")

    }

    func didSelectedPermission(permission: SPRequestPermissionType) {
        print("didSelectedPermission")

    }

}

what delegate do I forget ?

jonajgs commented 6 years ago

@IvanVorobei

I have another question, I have a UISwitch in my uiview, when the switch is disabled and I change the switch to active, i dont know how restart the app, because, i have in my appDelegate a geofence monitoring, but at the start the app dont have the permissions, I searching the way to refresh the app or any other idea, do you have help me please ?