Skip to content

Commit

Permalink
Update: handling logic for alwayAllowPermission in iOS. (#5)
Browse files Browse the repository at this point in the history
* Update: handling logic for alwayAllowPermission in iOS.

* Update: Access Modifier to internal of 'previousAuthorizationStatus'.

* Update: ABCLocationExt.kt code convention.

Co-authored-by: HanPro <[email protected]>
  • Loading branch information
HanSJin and HanPro authored Nov 23, 2021
1 parent 824d66b commit 8b0d6ee
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import org.jetbrains.kotlin.cli.common.toBooleanLenient
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget

val isSnapshotUpload = System.getProperty("snapshot").toBooleanLenient() ?: false
val libVersion = "0.2.5"
val libVersion = "0.2.6"
val gitName = "abc-${project.name}"

buildscript {
Expand Down
2 changes: 1 addition & 1 deletion kmm_location.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'kmm_location'
spec.version = '0.2.5'
spec.version = '0.2.6'
spec.homepage = ''
spec.source = { :git => "Not Published", :tag => "Cocoapods/#{spec.name}/#{spec.version}" }
spec.authors = ''
Expand Down
8 changes: 6 additions & 2 deletions sample/iosApp/iosApp/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
ABCLocation.Companion().requiredPermission = .authorizedalways
ABCLocation.Companion().onAlwaysAllowsPermissionRequired(target: self) {
print("onAlwaysAllowsPermissionRequired")
}
}

@IBAction func tappedCurrent(_ sender: UIButton) {
Expand All @@ -28,7 +31,9 @@ class ViewController: UIViewController {
print("onLocationUnavailable")
showPermissionDeniedAlert()
}
.onPermissionUpdated(target: <#T##Any#>, block: <#T##(KotlinBoolean) -> Void#>)
.onPermissionUpdated(target: self, block: {
print("onPermissionUpdated. Granted:", $0)
})
.currentLocation { [unowned self] data in
print("location coordinates", Date(), data.coordinates)
locationLabel.text = "Single \(data.coordinates.latitude)\n\(locationLabel.text!)"
Expand All @@ -45,7 +50,6 @@ class ViewController: UIViewController {
print("location coordinates", Date(), data.coordinates)
locationLabel.text = "Continuous \(data.coordinates.latitude)\n\(locationLabel.text!)"
}
.
.startLocationUpdating()
}

Expand Down
2 changes: 1 addition & 1 deletion sample/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
kotlin("native.cocoapods")
}

val abcLocationLib = "com.linecorp.abc:kmm-location:0.2.4"
val abcLocationLib = "com.linecorp.abc:kmm-location:0.2.6"

version = "1.0"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.linecorp.abc.location

import com.linecorp.abc.location.extension.previousAuthorizationStatus
import com.linecorp.abc.location.extension.requiredPermission
import kotlinx.cinterop.useContents
import platform.CoreLocation.*
Expand All @@ -25,6 +26,7 @@ internal class CLLocationManagerDelegate: NSObject(), CLLocationManagerDelegateP
val isGranted = ABCLocation.requiredPermission == status ||
LocationAuthorizationStatus.AuthorizedAlways == status
ABCLocation.notifyOnPermissionUpdated(isGranted)
ABCLocation.previousAuthorizationStatus = status
ABCLocation.startLocationUpdating()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ internal actual class LocationManager {
// -------------------------------------------------------------------------------------------

var requiredPermission = LocationAuthorizationStatus.AuthorizedAlways
var previousAuthorizationStatus = LocationAuthorizationStatus.NotSet

fun onAlwaysAllowsPermissionRequired(
target: Any,
Expand Down Expand Up @@ -100,8 +101,6 @@ internal actual class LocationManager {

private val onAlwaysAllowsPermissionRequiredBlockMap = NativeAtomicReference(mapOf<Any, OnAlwaysAllowsPermissionRequiredBlock>())

private var previousAuthorizationStatus = LocationAuthorizationStatus.NotSet

private fun notifyOnAlwaysAllowsPermissionRequired() {
onAlwaysAllowsPermissionRequiredBlockMap.value.forEach { it.value() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ fun ABCLocation.Companion.onAlwaysAllowsPermissionRequired(
}

fun ABCLocation.Companion.removeOnAlwaysAllowsPermissionRequired(target: Any) =
locationManager.removeOnAlwaysAllowsPermissionRequired(target)
locationManager.removeOnAlwaysAllowsPermissionRequired(target)

internal var ABCLocation.Companion.previousAuthorizationStatus: LocationAuthorizationStatus
get() = locationManager.previousAuthorizationStatus
set(value) { locationManager.previousAuthorizationStatus = value }

0 comments on commit 8b0d6ee

Please sign in to comment.