expo-cellular 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -10,6 +10,12 @@
10
10
 
11
11
  ### 💡 Others
12
12
 
13
+ ## 4.1.0 — 2021-12-03
14
+
15
+ ### 💡 Others
16
+
17
+ - Removed legacy Objective-C implementation and changed the pod name to `ExpoCellular`. ([#15082](https://github.com/expo/expo/pull/15082) by [@tsapeta](https://github.com/tsapeta))
18
+
13
19
  ## 4.0.0 — 2021-09-28
14
20
 
15
21
  ### 🛠 Breaking changes
package/README.md CHANGED
@@ -13,7 +13,7 @@ For managed [managed](https://docs.expo.io/versions/latest/introduction/managed-
13
13
 
14
14
  # Installation in bare React Native projects
15
15
 
16
- For bare React Native projects, you must ensure that you have [installed and configured the `react-native-unimodules` package](https://github.com/expo/expo/tree/master/packages/react-native-unimodules) before continuing.
16
+ For bare React Native projects, you must ensure that you have [installed and configured the `expo` package](https://docs.expo.dev/bare/installing-expo-modules/) before continuing.
17
17
 
18
18
  ### Add the package to your npm dependencies
19
19
 
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
3
3
  apply plugin: 'maven'
4
4
 
5
5
  group = 'host.exp.exponent'
6
- version = '4.0.0'
6
+ version = '4.1.0'
7
7
 
8
8
  buildscript {
9
9
  // Simple helper that allows the root project to override versions declared by this library.
@@ -53,11 +53,15 @@ android {
53
53
  targetCompatibility JavaVersion.VERSION_1_8
54
54
  }
55
55
 
56
+ kotlinOptions {
57
+ jvmTarget = JavaVersion.VERSION_1_8
58
+ }
59
+
56
60
  defaultConfig {
57
61
  minSdkVersion safeExtGet("minSdkVersion", 21)
58
62
  targetSdkVersion safeExtGet("targetSdkVersion", 30)
59
63
  versionCode 11
60
- versionName '4.0.0'
64
+ versionName '4.1.0'
61
65
  }
62
66
  lintOptions {
63
67
  abortOnError false
@@ -6,68 +6,62 @@ import android.net.sip.SipManager
6
6
  import android.os.Build
7
7
  import android.telephony.TelephonyManager
8
8
  import android.util.Log
9
- import expo.modules.core.ExportedModule
10
- import expo.modules.core.Promise
11
- import expo.modules.core.interfaces.ExpoMethod
12
- import expo.modules.core.interfaces.RegistryLifecycleListener
13
- import java.util.*
9
+ import expo.modules.kotlin.modules.Module
10
+ import expo.modules.kotlin.modules.ModuleDefinition
14
11
 
15
- class CellularModule(private val mContext: Context) : ExportedModule(mContext), RegistryLifecycleListener {
16
- override fun getName(): String = "ExpoCellular"
12
+ const val moduleName = "ExpoCellular"
17
13
 
18
- private fun telephonyManager() =
19
- (mContext.getSystemService(Context.TELEPHONY_SERVICE) as? TelephonyManager).takeIf {
20
- it?.simState == TelephonyManager.SIM_STATE_READY
14
+ class CellularModule : Module() {
15
+ override fun definition() = ModuleDefinition {
16
+ name(moduleName)
17
+ constants {
18
+ val telephonyManager = telephonyManager()
19
+ mapOf(
20
+ "allowsVoip" to SipManager.isVoipSupported(context),
21
+ "isoCountryCode" to telephonyManager?.simCountryIso,
22
+ "carrier" to telephonyManager?.simOperatorName,
23
+ "mobileCountryCode" to telephonyManager?.simOperator?.substring(0, 3),
24
+ "mobileNetworkCode" to telephonyManager?.simOperator?.substring(3)
25
+ )
21
26
  }
22
27
 
23
- override fun getConstants() =
24
- HashMap<String, Any?>().apply {
25
- val telephonyManager = telephonyManager()
26
- put("allowsVoip", SipManager.isVoipSupported(mContext))
27
- put("isoCountryCode", telephonyManager?.simCountryIso)
28
- put("carrier", telephonyManager?.simOperatorName)
29
- put("mobileCountryCode", telephonyManager?.simOperator?.substring(0, 3))
30
- put("mobileNetworkCode", telephonyManager?.simOperator?.substring(3))
28
+ function("getCellularGenerationAsync") {
29
+ try {
30
+ getCurrentGeneration()
31
+ } catch (e: SecurityException) {
32
+ Log.w(moduleName, "READ_PHONE_STATE permission is required to acquire network type", e)
33
+ CellularGeneration.UNKNOWN.value
34
+ }
31
35
  }
32
36
 
33
- @ExpoMethod
34
- fun getCellularGenerationAsync(promise: Promise) {
35
- try {
36
- promise.resolve(getCurrentGeneration())
37
- } catch (e: SecurityException) {
38
- Log.w(name, "READ_PHONE_STATE permission is required to acquire network type", e)
39
- promise.resolve(CellularGeneration.UNKNOWN.value)
37
+ function("allowsVoipAsync") {
38
+ SipManager.isVoipSupported(context)
40
39
  }
41
- }
42
40
 
43
- @ExpoMethod
44
- fun allowsVoipAsync(promise: Promise) {
45
- promise.resolve(SipManager.isVoipSupported(mContext))
46
- }
41
+ function("getIsoCountryCodeAsync") {
42
+ telephonyManager()?.simCountryIso
43
+ }
47
44
 
48
- @ExpoMethod
49
- fun getIsoCountryCodeAsync(promise: Promise) {
50
- val telephonyManager = telephonyManager()
51
- promise.resolve(telephonyManager?.simCountryIso)
52
- }
45
+ function("getCarrierNameAsync") {
46
+ telephonyManager()?.simOperatorName
47
+ }
53
48
 
54
- @ExpoMethod
55
- fun getCarrierNameAsync(promise: Promise) {
56
- val telephonyManager = telephonyManager()
57
- promise.resolve(telephonyManager?.simOperatorName)
58
- }
49
+ function("getMobileCountryCodeAsync") {
50
+ telephonyManager()?.simOperator?.substring(0, 3)
51
+ }
59
52
 
60
- @ExpoMethod
61
- fun getMobileCountryCodeAsync(promise: Promise) {
62
- val telephonyManager = telephonyManager()
63
- promise.resolve(telephonyManager?.simOperator?.substring(0, 3))
53
+ function("getMobileNetworkCodeAsync") {
54
+ telephonyManager()?.simOperator?.substring(3)
55
+ }
64
56
  }
65
57
 
66
- @ExpoMethod
67
- fun getMobileNetworkCodeAsync(promise: Promise) {
68
- val telephonyManager = telephonyManager()
69
- promise.resolve(telephonyManager?.simOperator?.substring(3))
70
- }
58
+ private fun telephonyManager() =
59
+ (context.getSystemService(Context.TELEPHONY_SERVICE) as? TelephonyManager).takeIf {
60
+ it?.simState == TelephonyManager.SIM_STATE_READY
61
+ }
62
+
63
+ private val context
64
+ get() = requireNotNull(appContext.reactContext)
71
65
 
72
66
  @SuppressLint("MissingPermission")
73
67
  private fun getCurrentGeneration(): Int {
@@ -16,10 +16,7 @@ export default {
16
16
  return null;
17
17
  },
18
18
  async getCellularGenerationAsync() {
19
- const connection = navigator['connection'] ||
20
- navigator['mozConnection'] ||
21
- navigator['webkitConnection'] ||
22
- null;
19
+ const connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection || null;
23
20
  if (connection !== null) {
24
21
  switch (connection.effectiveType) {
25
22
  case 'slow-2g':
@@ -1 +1 @@
1
- {"version":3,"file":"ExpoCellular.web.js","sourceRoot":"","sources":["../src/ExpoCellular.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,eAAe;IACb,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,OAAO;QACT,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,cAAc;QAChB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,iBAAiB;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,iBAAiB;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,KAAK,CAAC,0BAA0B;QAC9B,MAAM,UAAU,GACd,SAAS,CAAC,YAAY,CAAC;YACvB,SAAS,CAAC,eAAe,CAAC;YAC1B,SAAS,CAAC,kBAAkB,CAAC;YAC7B,IAAI,CAAC;QACP,IAAI,UAAU,KAAK,IAAI,EAAE;YACvB,QAAQ,UAAU,CAAC,aAAa,EAAE;gBAChC,KAAK,SAAS,CAAC;gBACf,KAAK,IAAI;oBACP,OAAO,kBAAkB,CAAC,WAAW,CAAC;gBACxC,KAAK,IAAI;oBACP,OAAO,kBAAkB,CAAC,WAAW,CAAC;gBACxC,KAAK,IAAI;oBACP,OAAO,kBAAkB,CAAC,WAAW,CAAC;gBACxC;oBACE,OAAO,kBAAkB,CAAC,OAAO,CAAC;aACrC;SACF;aAAM;YACL,OAAO,kBAAkB,CAAC,OAAO,CAAC;SACnC;IACH,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,KAAK,CAAC,sBAAsB;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,KAAK,CAAC,mBAAmB;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,KAAK,CAAC,yBAAyB;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,KAAK,CAAC,yBAAyB;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAC","sourcesContent":["import { CellularGeneration } from './Cellular.types';\n\nexport default {\n get allowsVoip(): null {\n return null;\n },\n get carrier(): null {\n return null;\n },\n get isoCountryCode(): null {\n return null;\n },\n get mobileCountryCode(): null {\n return null;\n },\n get mobileNetworkCode(): null {\n return null;\n },\n async getCellularGenerationAsync(): Promise<CellularGeneration> {\n const connection =\n navigator['connection'] ||\n navigator['mozConnection'] ||\n navigator['webkitConnection'] ||\n null;\n if (connection !== null) {\n switch (connection.effectiveType) {\n case 'slow-2g':\n case '2g':\n return CellularGeneration.CELLULAR_2G;\n case '3g':\n return CellularGeneration.CELLULAR_3G;\n case '4g':\n return CellularGeneration.CELLULAR_4G;\n default:\n return CellularGeneration.UNKNOWN;\n }\n } else {\n return CellularGeneration.UNKNOWN;\n }\n },\n\n async allowsVoipAsync(): Promise<boolean | null> {\n return null;\n },\n async getIsoCountryCodeAsync(): Promise<string | null> {\n return null;\n },\n async getCarrierNameAsync(): Promise<string | null> {\n return null;\n },\n async getMobileCountryCodeAsync(): Promise<string | null> {\n return null;\n },\n async getMobileNetworkCodeAsync(): Promise<string | null> {\n return null;\n },\n};\n"]}
1
+ {"version":3,"file":"ExpoCellular.web.js","sourceRoot":"","sources":["../src/ExpoCellular.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,eAAe;IACb,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,OAAO;QACT,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,cAAc;QAChB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,iBAAiB;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,iBAAiB;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,KAAK,CAAC,0BAA0B;QAC9B,MAAM,UAAU,GACd,SAAS,CAAC,UAAU,IAAI,SAAS,CAAC,aAAa,IAAI,SAAS,CAAC,gBAAgB,IAAI,IAAI,CAAC;QACxF,IAAI,UAAU,KAAK,IAAI,EAAE;YACvB,QAAQ,UAAU,CAAC,aAAa,EAAE;gBAChC,KAAK,SAAS,CAAC;gBACf,KAAK,IAAI;oBACP,OAAO,kBAAkB,CAAC,WAAW,CAAC;gBACxC,KAAK,IAAI;oBACP,OAAO,kBAAkB,CAAC,WAAW,CAAC;gBACxC,KAAK,IAAI;oBACP,OAAO,kBAAkB,CAAC,WAAW,CAAC;gBACxC;oBACE,OAAO,kBAAkB,CAAC,OAAO,CAAC;aACrC;SACF;aAAM;YACL,OAAO,kBAAkB,CAAC,OAAO,CAAC;SACnC;IACH,CAAC;IAED,KAAK,CAAC,eAAe;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,KAAK,CAAC,sBAAsB;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,KAAK,CAAC,mBAAmB;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,KAAK,CAAC,yBAAyB;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,KAAK,CAAC,yBAAyB;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAC","sourcesContent":["import { CellularGeneration } from './Cellular.types';\n\nexport default {\n get allowsVoip(): null {\n return null;\n },\n get carrier(): null {\n return null;\n },\n get isoCountryCode(): null {\n return null;\n },\n get mobileCountryCode(): null {\n return null;\n },\n get mobileNetworkCode(): null {\n return null;\n },\n async getCellularGenerationAsync(): Promise<CellularGeneration> {\n const connection =\n navigator.connection || navigator.mozConnection || navigator.webkitConnection || null;\n if (connection !== null) {\n switch (connection.effectiveType) {\n case 'slow-2g':\n case '2g':\n return CellularGeneration.CELLULAR_2G;\n case '3g':\n return CellularGeneration.CELLULAR_3G;\n case '4g':\n return CellularGeneration.CELLULAR_4G;\n default:\n return CellularGeneration.UNKNOWN;\n }\n } else {\n return CellularGeneration.UNKNOWN;\n }\n },\n\n async allowsVoipAsync(): Promise<boolean | null> {\n return null;\n },\n async getIsoCountryCodeAsync(): Promise<string | null> {\n return null;\n },\n async getCarrierNameAsync(): Promise<string | null> {\n return null;\n },\n async getMobileCountryCodeAsync(): Promise<string | null> {\n return null;\n },\n async getMobileNetworkCodeAsync(): Promise<string | null> {\n return null;\n },\n};\n"]}
@@ -3,5 +3,8 @@
3
3
  "platforms": ["ios", "android", "web"],
4
4
  "ios": {
5
5
  "modulesClassNames": ["CellularModule"]
6
+ },
7
+ "android": {
8
+ "modulesClassNames": ["expo.modules.cellular.CellularModule"]
6
9
  }
7
10
  }
@@ -4,25 +4,32 @@ import ExpoModulesCore
4
4
  public class CellularModule: Module {
5
5
  public func definition() -> ModuleDefinition {
6
6
  name("ExpoCellular")
7
+
7
8
  constants {
8
9
  Self.getCurrentCellularInfo()
9
10
  }
10
- method("getCellularGenerationAsync") { () -> Int in
11
+
12
+ function("getCellularGenerationAsync") { () -> Int in
11
13
  Self.currentCellularGeneration().rawValue
12
14
  }
13
- method("allowsVoipAsync") { () -> Bool? in
15
+
16
+ function("allowsVoipAsync") { () -> Bool? in
14
17
  Self.currentCarrier()?.allowsVOIP
15
18
  }
16
- method("getIsoCountryCodeAsync") { () -> String? in
19
+
20
+ function("getIsoCountryCodeAsync") { () -> String? in
17
21
  Self.currentCarrier()?.isoCountryCode
18
22
  }
19
- method("getCarrierNameAsync") { () -> String? in
23
+
24
+ function("getCarrierNameAsync") { () -> String? in
20
25
  Self.currentCarrier()?.carrierName
21
26
  }
22
- method("getMobileCountryCodeAsync") { () -> String? in
27
+
28
+ function("getMobileCountryCodeAsync") { () -> String? in
23
29
  Self.currentCarrier()?.mobileCountryCode
24
30
  }
25
- method("getMobileNetworkCodeAsync") { () -> String? in
31
+
32
+ function("getMobileNetworkCodeAsync") { () -> String? in
26
33
  Self.currentCarrier()?.mobileNetworkCode
27
34
  }
28
35
  }
@@ -3,7 +3,7 @@ require 'json'
3
3
  package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
4
4
 
5
5
  Pod::Spec.new do |s|
6
- s.name = 'EXCellular'
6
+ s.name = 'ExpoCellular'
7
7
  s.version = package['version']
8
8
  s.summary = package['description']
9
9
  s.description = package['description']
@@ -19,13 +19,14 @@ Pod::Spec.new do |s|
19
19
 
20
20
  # Swift/Objective-C compatibility
21
21
  s.pod_target_xcconfig = {
22
- 'DEFINES_MODULE' => 'YES'
22
+ 'DEFINES_MODULE' => 'YES',
23
+ 'SWIFT_COMPILATION_MODE' => 'wholemodule'
23
24
  }
24
25
 
25
26
  if !$ExpoUseSources&.include?(package['name']) && ENV['EXPO_USE_SOURCE'].to_i == 0 && File.exist?("#{s.name}.xcframework") && Gem::Version.new(Pod::VERSION) >= Gem::Version.new('1.10.0')
26
- s.source_files = "#{s.name}/**/*.h"
27
+ s.source_files = "**/*.h"
27
28
  s.vendored_frameworks = "#{s.name}.xcframework"
28
29
  else
29
- s.source_files = "#{s.name}/**/*.{h,m,swift}"
30
+ s.source_files = "**/*.{h,m,swift}"
30
31
  end
31
32
  end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-cellular",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "Provides information about the user’s cellular service provider",
5
5
  "main": "build/Cellular.js",
6
6
  "types": "build/Cellular.d.ts",
@@ -29,8 +29,12 @@
29
29
  "author": "650 Industries, Inc.",
30
30
  "license": "MIT",
31
31
  "homepage": "https://docs.expo.dev/versions/latest/sdk/cellular/",
32
+ "dependencies": {},
32
33
  "devDependencies": {
33
34
  "expo-module-scripts": "^2.0.0"
34
35
  },
35
- "gitHead": "1fffde73411ee7a642b98f1506a8de921805d52b"
36
+ "peerDependencies": {
37
+ "expo": "*"
38
+ },
39
+ "gitHead": "2e5c6983b86d5ecfca028ba64002897d8adc2cc4"
36
40
  }
@@ -9,4 +9,4 @@ const withCellular = (config) => {
9
9
  ]);
10
10
  return config;
11
11
  };
12
- exports.default = config_plugins_1.createRunOncePlugin(withCellular, pkg.name, pkg.version);
12
+ exports.default = (0, config_plugins_1.createRunOncePlugin)(withCellular, pkg.name, pkg.version);
@@ -18,10 +18,7 @@ export default {
18
18
  },
19
19
  async getCellularGenerationAsync(): Promise<CellularGeneration> {
20
20
  const connection =
21
- navigator['connection'] ||
22
- navigator['mozConnection'] ||
23
- navigator['webkitConnection'] ||
24
- null;
21
+ navigator.connection || navigator.mozConnection || navigator.webkitConnection || null;
25
22
  if (connection !== null) {
26
23
  switch (connection.effectiveType) {
27
24
  case 'slow-2g':
@@ -0,0 +1,18 @@
1
+ // Expose this file as a module (see https://stackoverflow.com/a/59499895/4337317)
2
+ export {};
3
+
4
+ /**
5
+ * Handle deprecations and missing typings that not available in the main lib.dom.d.ts file.
6
+ */
7
+ declare global {
8
+ type EffectiveConnectionType = '2g' | '3g' | '4g' | 'slow-2g';
9
+
10
+ interface NetworkInformation {
11
+ readonly effectiveType: EffectiveConnectionType;
12
+ }
13
+
14
+ interface Navigator {
15
+ readonly mozConnection?: NetworkInformation;
16
+ readonly webkitConnection?: NetworkInformation;
17
+ }
18
+ }
@@ -1,9 +0,0 @@
1
- package expo.modules.cellular
2
-
3
- import android.content.Context
4
- import expo.modules.core.BasePackage
5
-
6
- class CellularPackage : BasePackage() {
7
- override fun createExportedModules(context: Context) =
8
- listOf(CellularModule(context))
9
- }
@@ -1,23 +0,0 @@
1
- // Copyright © 2018 650 Industries. All rights reserved.
2
-
3
- #import <ExpoModulesCore/EXExportedModule.h>
4
- #import <ExpoModulesCore/EXModuleRegistryConsumer.h>
5
-
6
- NS_ASSUME_NONNULL_BEGIN
7
-
8
- // Keep this enum in sync with JavaScript
9
- // Based on the EffectiveConnectionType enum described in the W3C Network Information API spec
10
- // (https://wicg.github.io/netinfo/).
11
- typedef NS_ENUM(NSInteger, EXCellularGeneration) {
12
- EXCellularGenerationUnknown = 0,
13
- EXCellularGeneration2G,
14
- EXCellularGeneration3G,
15
- EXCellularGeneration4G,
16
- EXCellularGeneration5G,
17
- };
18
-
19
- @interface EXCellularModule : EXExportedModule <EXModuleRegistryConsumer>
20
-
21
- @end
22
-
23
- NS_ASSUME_NONNULL_END
@@ -1,153 +0,0 @@
1
- // Copyright 2018-present 650 Industries. All rights reserved.
2
-
3
- #import <EXCellular/EXCellularModule.h>
4
-
5
- #import <CoreTelephony/CTCarrier.h>
6
- #import <CoreTelephony/CTTelephonyNetworkInfo.h>
7
-
8
-
9
- @interface EXCellularModule ()
10
-
11
- @property (nonatomic, weak) EXModuleRegistry *moduleRegistry;
12
-
13
- @end
14
-
15
- @implementation EXCellularModule
16
-
17
- EX_EXPORT_MODULE(ExpoCellular);
18
-
19
- - (void)setModuleRegistry:(EXModuleRegistry *)moduleRegistry
20
- {
21
- _moduleRegistry = moduleRegistry;
22
- }
23
-
24
- - (NSDictionary *)constantsToExport
25
- {
26
- CTCarrier *carrier = [self carrier];
27
-
28
- return [self getCurrentCellularInfo];
29
- }
30
-
31
- EX_EXPORT_METHOD_AS(getCellularGenerationAsync, getCellularGenerationAsyncWithResolver:(EXPromiseResolveBlock)resolve rejecter:(EXPromiseRejectBlock)reject)
32
- {
33
- resolve(@([[self class] getCellularGeneration]));
34
- }
35
-
36
- EX_EXPORT_METHOD_AS(allowsVoipAsync, allowsVoipAsyncWithResolver:(EXPromiseResolveBlock)resolve rejecter:(EXPromiseRejectBlock)reject)
37
- {
38
- resolve(@([self allowsVoip]));
39
- }
40
-
41
- EX_EXPORT_METHOD_AS(getIsoCountryCodeAsync, getIsoCountryCodeAsyncWithResolver:(EXPromiseResolveBlock)resolve rejecter:(EXPromiseRejectBlock)reject)
42
- {
43
- resolve([self getIsoCountryCode]);
44
- }
45
-
46
- EX_EXPORT_METHOD_AS(getCarrierNameAsync, getCarrierNameAsyncWithResolver:(EXPromiseResolveBlock)resolve rejecter:(EXPromiseRejectBlock)reject)
47
- {
48
- resolve([self getCarrierName]);
49
- }
50
-
51
- EX_EXPORT_METHOD_AS(getMobileCountryCodeAsync, getMobileCountryCodeAsyncWithResolver:(EXPromiseResolveBlock)resolve rejecter:(EXPromiseRejectBlock)reject)
52
- {
53
- resolve([self getMobileCountryCode]);
54
- }
55
-
56
- EX_EXPORT_METHOD_AS(getMobileNetworkCodeAsync, getMobileNetworkCodeAsyncWithResolver:(EXPromiseResolveBlock)resolve rejecter:(EXPromiseRejectBlock)reject)
57
- {
58
- resolve([self getMobileNetworkCode]);
59
- }
60
-
61
- + (EXCellularGeneration)getCellularGeneration
62
- {
63
- CTTelephonyNetworkInfo *netinfo = [[CTTelephonyNetworkInfo alloc] init];
64
- NSString *serviceCurrentRadioAccessTechnology;
65
- if (@available(iOS 12.0, *)) {
66
- serviceCurrentRadioAccessTechnology = netinfo.serviceCurrentRadioAccessTechnology.allValues.firstObject;
67
- } else {
68
- // Fallback on earlier versions
69
- serviceCurrentRadioAccessTechnology = netinfo.currentRadioAccessTechnology;
70
- }
71
-
72
- if (netinfo) {
73
- if ([serviceCurrentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyGPRS] ||
74
- [serviceCurrentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyEdge] ||
75
- [serviceCurrentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMA1x]) {
76
- return EXCellularGeneration2G;
77
- } else if ([serviceCurrentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyWCDMA] ||
78
- [serviceCurrentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyHSDPA] ||
79
- [serviceCurrentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyHSUPA] ||
80
- [serviceCurrentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORev0] ||
81
- [serviceCurrentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORevA] ||
82
- [serviceCurrentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyCDMAEVDORevB] ||
83
- [serviceCurrentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyeHRPD]) {
84
- return EXCellularGeneration3G;
85
- } else if ([serviceCurrentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyLTE]) {
86
- return EXCellularGeneration4G;
87
- } else if (@available(iOS 14.1, *) &&
88
- ([serviceCurrentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyNRNSA] ||
89
- [serviceCurrentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyNR])) {
90
- return EXCellularGeneration5G;
91
- }
92
- }
93
- return EXCellularGenerationUnknown;
94
- }
95
-
96
-
97
- - (CTCarrier *)carrier
98
- {
99
- CTTelephonyNetworkInfo *netinfo = [[CTTelephonyNetworkInfo alloc] init];
100
-
101
- if (@available(iOS 12.0, *)) {
102
- for (NSString *key in netinfo.serviceSubscriberCellularProviders) {
103
- CTCarrier *carrier = netinfo.serviceSubscriberCellularProviders[key];
104
- if (carrier.carrierName != nil) {
105
- return carrier;
106
- }
107
- }
108
-
109
- return [[netinfo.serviceSubscriberCellularProviders objectEnumerator] nextObject];
110
- }
111
-
112
- return netinfo.subscriberCellularProvider;
113
- }
114
-
115
- - (NSDictionary *)getCurrentCellularInfo
116
- {
117
- CTCarrier *carrier = [self carrier];
118
-
119
- return @{
120
- @"allowsVoip": @(carrier.allowsVOIP),
121
- @"carrier": EXNullIfNil(carrier.carrierName),
122
- @"isoCountryCode": EXNullIfNil(carrier.isoCountryCode),
123
- @"mobileCountryCode": EXNullIfNil(carrier.mobileCountryCode),
124
- @"mobileNetworkCode": EXNullIfNil(carrier.mobileNetworkCode),
125
- };
126
- }
127
-
128
- - (BOOL)allowsVoip
129
- {
130
- return [self carrier].allowsVOIP;
131
- }
132
-
133
- - (NSString *)getIsoCountryCode
134
- {
135
- return [self carrier].isoCountryCode;
136
- }
137
-
138
- - (NSString *)getCarrierName
139
- {
140
- return [self carrier].carrierName;
141
- }
142
-
143
- - (NSString *)getMobileCountryCode
144
- {
145
- return [self carrier].mobileCountryCode;
146
- }
147
-
148
- - (NSString *)getMobileNetworkCode
149
- {
150
- return [self carrier].mobileNetworkCode;
151
- }
152
-
153
- @end