@@ -32,36 +32,48 @@ class FlutterAdvertisingIdPlugin : FlutterPlugin, MethodCallHandler, CoroutineSc
3232 }
3333
3434 override fun onMethodCall (call : MethodCall , result : Result ) {
35- if (call.method == " getAdvertisingId" ) {
36- applicationContext?.run {
37- launch {
38- val adInfo = withContext(Dispatchers .IO ) {
39- AdvertisingIdClient .getAdvertisingIdInfo(this @run.applicationContext)
40- }
41- withContext(Dispatchers .Main ) {
42- result.success(adInfo.id)
35+ when (call.method) {
36+ " getAdvertisingId" -> {
37+ applicationContext?.run {
38+ launch {
39+ val adInfo = withContext(Dispatchers .IO ) {
40+ runCatching {
41+ AdvertisingIdClient .getAdvertisingIdInfo(this @run.applicationContext)
42+ }.getOrNull()
43+ }
44+ withContext(Dispatchers .Main ) {
45+ result.success(adInfo?.id)
46+ }
4347 }
48+ } ? : run {
49+ result.success(null )
4450 }
45- } ? : run {
46- result.success(null )
4751 }
48- } else if (call.method == " getAdvertisingId" ) {
49- applicationContext?.run {
50- launch {
51- val adInfo = withContext(Dispatchers .IO ) {
52- AdvertisingIdClient .getAdvertisingIdInfo(this @run.applicationContext)
53- }
54- withContext(Dispatchers .Main ) {
55- result.success(adInfo.isLimitAdTrackingEnabled)
52+
53+ " limitAdTrackingEnabled" -> {
54+ applicationContext?.run {
55+ launch {
56+ val adInfo = withContext(Dispatchers .IO ) {
57+ runCatching {
58+ AdvertisingIdClient .getAdvertisingIdInfo(this @run.applicationContext)
59+ }.getOrNull()
60+ }
61+ withContext(Dispatchers .Main ) {
62+ result.success(adInfo?.isLimitAdTrackingEnabled ? : false )
63+ }
5664 }
65+ } ? : run {
66+ result.success(null )
5767 }
58- } ? : run {
59- result.success(null )
6068 }
61- } else if (call.method == " authorizationStatus" ) {
62- result.success(3 )
63- } else {
64- result.notImplemented()
69+
70+ " authorizationStatus" -> {
71+ result.success(3 )
72+ }
73+
74+ else -> {
75+ result.notImplemented()
76+ }
6577 }
6678 }
6779
0 commit comments