Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

throw exception when calling finish before pollTag done #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class FlutterNfcKitPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
private var ndefTechnology: Ndef? = null
private var mifareInfo: MifareInfo? = null

private var onUserCancelled: (() -> Unit)? = null

private fun TagTechnology.transceive(data: ByteArray, timeout: Int?): ByteArray {
if (timeout != null) {
try {
Expand Down Expand Up @@ -119,7 +121,10 @@ class FlutterNfcKitPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
}

"finish" -> {
pollingTimeoutTask?.cancel()
val isPolling = pollingTimeoutTask?.cancel()
if (isPolling == true) {
onUserCancelled?.invoke()
}
thread {
try {
val tagTech = tagTechnology
Expand Down Expand Up @@ -427,7 +432,10 @@ class FlutterNfcKitPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
}

override fun onDetachedFromActivity() {
pollingTimeoutTask?.cancel()
val isPolling = pollingTimeoutTask?.cancel()
if (isPolling == true) {
onUserCancelled?.invoke()
}
pollingTimeoutTask = null
tagTechnology = null
ndefTechnology = null
Expand All @@ -444,9 +452,18 @@ class FlutterNfcKitPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
if (activity.get() != null) {
nfcAdapter.disableReaderMode(activity.get())
}
onUserCancelled = null
result.error("408", "Polling tag timeout", null)
}

onUserCancelled = {
if (activity.get() != null) {
nfcAdapter.disableReaderMode(activity.get())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about change to

activity.get()?.let { nfcAdapter.disabledReaderMode(it) }

}
onUserCancelled = null
result.error("600", "User cancelled", null)
}

nfcAdapter.enableReaderMode(activity.get(), { tag ->
pollingTimeoutTask?.cancel()

Expand Down
Loading