Last active
July 6, 2022 05:17
-
-
Save alkozin/eacac508ba917936c9dfec24907c52b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Look to geolocation permissions request to illustrate. | |
//Request is constructed according to `with` object | |
// | |
//Ask always permissions only if `ask` `with` `CLAuthorizationStatus.authorizedAlways` input argument | |
//Otherwise `ask` only in use permissions | |
// | |
extension CLAuthorizationStatus: Asking { | |
static func ask<E>(with: Any?, in pipe: Pipe, expect: Expect<E>) { | |
let source = with as? CLLocationManager ?? pipe.get() | |
switch with as? CLAuthorizationStatus { | |
case .authorizedAlways: | |
source.requestAlwaysAuthorization() | |
case .authorizedWhenInUse, .none: | |
source.requestWhenInUseAuthorization() | |
default: | |
break | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment