Skip to content

Instantly share code, notes, and snippets.

View janakaaleph's full-sized avatar
🎯
Probably coding

Janaka Jayasuriya janakaaleph

🎯
Probably coding
View GitHub Profile
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
switch manager.authorizationStatus() {
case .authorizedAlways:
print("Always authorized.")
case .authorizedWhenInUse:
print("Authorization granted only when app is in use.")
case .denied, .notDetermined, .restricted:
print("Not authorized.")
@unknown default:
print("Unknown.")
if locationManager.accuracyAuthorization == .reducedAccuracy {
let alertController = UIAlertController(title: "Alert", message: "Need your exact location to start navigation", preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .default) { (_) in
guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else {
return
}
if UIApplication.shared.canOpenURL(settingsUrl) {
UIApplication.shared.open(settingsUrl, completionHandler: { (success) in
// Successfully navigated to settings
})
if locationManager.accuracyAuthorization == .reducedAccuracy {
locationManager.requestTemporaryFullAccuracyAuthorization(withPurposeKey: "wantsToDeliverFoodToDoorStep") { (error) in
// Use location with full accuracy
}
}
@janakaaleph
janakaaleph / Main.kt
Last active July 21, 2020 02:18
If and When in Kotlin
fun main() {
println("If Expression")
val a = 100
val b = 200
/**
* COMPILATION ERROR: 'if' must have both main and 'else' branches if used as an expression.
*/
val maxValue = if (b > a) "b is greater"