@movsesiv/capacitor-mock-location-check 1.0.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/CapacitorMockLocationCheck.podspec +17 -0
- package/Package.swift +28 -0
- package/README.md +33 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +5 -0
- package/android/src/main/java/com/movsesiv/capacitormocklocationcheck/MockLocationCheckPlugin.java +102 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +25 -0
- package/dist/esm/definitions.d.ts +5 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +7 -0
- package/dist/esm/web.js +10 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +24 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +27 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/MockLocationCheckPlugin/MockLocationCheckPlugin.swift +63 -0
- package/ios/Tests/MockLocationCheckPluginTests/MockLocationCheckPluginTests.swift +15 -0
- package/package.json +80 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'CapacitorMockLocationCheck'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '15.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.1'
|
|
17
|
+
end
|
package/Package.swift
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
import PackageDescription
|
|
3
|
+
|
|
4
|
+
let package = Package(
|
|
5
|
+
name: "CapacitorMockLocationCheck",
|
|
6
|
+
platforms: [.iOS(.v15)],
|
|
7
|
+
products: [
|
|
8
|
+
.library(
|
|
9
|
+
name: "CapacitorMockLocationCheck",
|
|
10
|
+
targets: ["MockLocationCheckPlugin"])
|
|
11
|
+
],
|
|
12
|
+
dependencies: [
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", branch: "main")
|
|
14
|
+
],
|
|
15
|
+
targets: [
|
|
16
|
+
.target(
|
|
17
|
+
name: "MockLocationCheckPlugin",
|
|
18
|
+
dependencies: [
|
|
19
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
+
.product(name: "Cordova", package: "capacitor-swift-pm")
|
|
21
|
+
],
|
|
22
|
+
path: "ios/Sources/MockLocationCheckPlugin"),
|
|
23
|
+
.testTarget(
|
|
24
|
+
name: "MockLocationCheckPluginTests",
|
|
25
|
+
dependencies: ["MockLocationCheckPlugin"],
|
|
26
|
+
path: "ios/Tests/MockLocationCheckPluginTests")
|
|
27
|
+
]
|
|
28
|
+
)
|
package/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# capacitor-mock-location-check
|
|
2
|
+
|
|
3
|
+
Capacitor plugin allowing to check if location is mocked
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install capacitor-mock-location-check
|
|
9
|
+
npx cap sync
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## API
|
|
13
|
+
|
|
14
|
+
<docgen-index>
|
|
15
|
+
|
|
16
|
+
* [`isLocationMocked()`](#islocationmocked)
|
|
17
|
+
|
|
18
|
+
</docgen-index>
|
|
19
|
+
|
|
20
|
+
<docgen-api>
|
|
21
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
22
|
+
|
|
23
|
+
### isLocationMocked()
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
isLocationMocked() => Promise<{ isLocationMocked: boolean; }>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Returns:** <code>Promise<{ isLocationMocked: boolean; }></code>
|
|
30
|
+
|
|
31
|
+
--------------------
|
|
32
|
+
|
|
33
|
+
</docgen-api>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.2.1'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
namespace "com.movsesiv.capacitormocklocationcheck"
|
|
22
|
+
compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
|
|
26
|
+
versionCode 1
|
|
27
|
+
versionName "1.0"
|
|
28
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
+
}
|
|
30
|
+
buildTypes {
|
|
31
|
+
release {
|
|
32
|
+
minifyEnabled false
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
lintOptions {
|
|
37
|
+
abortOnError false
|
|
38
|
+
}
|
|
39
|
+
compileOptions {
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
repositories {
|
|
46
|
+
google()
|
|
47
|
+
mavenCentral()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
dependencies {
|
|
52
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
|
+
implementation project(':capacitor-android')
|
|
54
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
+
testImplementation "junit:junit:$junitVersion"
|
|
56
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
57
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
58
|
+
}
|
package/android/src/main/java/com/movsesiv/capacitormocklocationcheck/MockLocationCheckPlugin.java
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
package com.movsesiv.capacitormocklocationcheck;
|
|
2
|
+
|
|
3
|
+
import android.Manifest;
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.content.pm.PackageManager;
|
|
6
|
+
import android.location.Location;
|
|
7
|
+
import android.location.LocationManager;
|
|
8
|
+
import android.os.Build;
|
|
9
|
+
import android.util.Log;
|
|
10
|
+
|
|
11
|
+
import androidx.core.content.ContextCompat;
|
|
12
|
+
|
|
13
|
+
import com.getcapacitor.JSObject;
|
|
14
|
+
import com.getcapacitor.Plugin;
|
|
15
|
+
import com.getcapacitor.PluginCall;
|
|
16
|
+
import com.getcapacitor.PluginMethod;
|
|
17
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
18
|
+
import com.getcapacitor.annotation.Permission;
|
|
19
|
+
import com.getcapacitor.annotation.PermissionCallback;
|
|
20
|
+
|
|
21
|
+
import java.util.List;
|
|
22
|
+
|
|
23
|
+
@CapacitorPlugin(name = "MockLocationCheck", permissions = {@Permission(alias = "location", strings = {Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION})})
|
|
24
|
+
public class MockLocationCheckPlugin extends Plugin {
|
|
25
|
+
|
|
26
|
+
@PluginMethod
|
|
27
|
+
public void isLocationMocked(PluginCall call) {
|
|
28
|
+
// Check if location permissions are granted
|
|
29
|
+
if (!hasLocationPermission()) {
|
|
30
|
+
// Permissions not granted, request permissions
|
|
31
|
+
requestAllPermissions(call, "permissionCallback");
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Permissions are granted, proceed to check if location is mocked
|
|
36
|
+
checkIfLocationIsMocked(call);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@PermissionCallback
|
|
40
|
+
private void permissionCallback(PluginCall call) {
|
|
41
|
+
if (hasLocationPermission()) {
|
|
42
|
+
// Permissions have been granted, proceed to check if location is mocked
|
|
43
|
+
checkIfLocationIsMocked(call);
|
|
44
|
+
} else {
|
|
45
|
+
// Permissions not granted, reject the call
|
|
46
|
+
call.reject("Location permissions not granted.");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private void checkIfLocationIsMocked(PluginCall call) {
|
|
51
|
+
Location location = getCurrentLocation();
|
|
52
|
+
|
|
53
|
+
if (location == null) {
|
|
54
|
+
call.reject("Location not available.");
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
boolean isMock = false;
|
|
59
|
+
|
|
60
|
+
Log.i("MockLocationCheck", "Location obtained: " + location.toString());
|
|
61
|
+
|
|
62
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
|
63
|
+
isMock = location.isFromMockProvider();
|
|
64
|
+
Log.i("MockLocationCheck", "isFromMockProvider: " + isMock);
|
|
65
|
+
} else {
|
|
66
|
+
String provider = location.getProvider();
|
|
67
|
+
isMock = !provider.equals("gps") && !provider.equals("network");
|
|
68
|
+
Log.i("MockLocationCheck", "Provider: " + provider + ", isMock: " + isMock);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
JSObject ret = new JSObject();
|
|
72
|
+
ret.put("isLocationMocked", isMock);
|
|
73
|
+
call.resolve(ret);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private Location getCurrentLocation() {
|
|
77
|
+
LocationManager locationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
|
|
78
|
+
List<String> providers = locationManager.getProviders(true);
|
|
79
|
+
Location bestLocation = null;
|
|
80
|
+
|
|
81
|
+
for (String provider : providers) {
|
|
82
|
+
try {
|
|
83
|
+
Location location = locationManager.getLastKnownLocation(provider);
|
|
84
|
+
if (location == null) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (bestLocation == null || location.getAccuracy() < bestLocation.getAccuracy()) {
|
|
88
|
+
bestLocation = location;
|
|
89
|
+
}
|
|
90
|
+
} catch (SecurityException e) {
|
|
91
|
+
// Handle the exception if permissions are not granted
|
|
92
|
+
e.printStackTrace();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return bestLocation;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private boolean hasLocationPermission() {
|
|
99
|
+
Context context = getContext();
|
|
100
|
+
return ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
File without changes
|
package/dist/docs.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"api": {
|
|
3
|
+
"name": "MockLocationCheckPlugin",
|
|
4
|
+
"slug": "mocklocationcheckplugin",
|
|
5
|
+
"docs": "",
|
|
6
|
+
"tags": [],
|
|
7
|
+
"methods": [
|
|
8
|
+
{
|
|
9
|
+
"name": "isLocationMocked",
|
|
10
|
+
"signature": "() => Promise<{ isLocationMocked: boolean; }>",
|
|
11
|
+
"parameters": [],
|
|
12
|
+
"returns": "Promise<{ isLocationMocked: boolean; }>",
|
|
13
|
+
"tags": [],
|
|
14
|
+
"docs": "",
|
|
15
|
+
"complexTypes": [],
|
|
16
|
+
"slug": "islocationmocked"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"properties": []
|
|
20
|
+
},
|
|
21
|
+
"interfaces": [],
|
|
22
|
+
"enums": [],
|
|
23
|
+
"typeAliases": [],
|
|
24
|
+
"pluginConfigs": []
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface MockLocationCheckPlugin {\n isLocationMocked(): Promise<{isLocationMocked: boolean}>;\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
const MockLocationCheck = registerPlugin('MockLocationCheck', {
|
|
3
|
+
web: () => import('./web').then((m) => new m.MockLocationCheckWeb()),
|
|
4
|
+
});
|
|
5
|
+
export * from './definitions';
|
|
6
|
+
export { MockLocationCheck };
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,iBAAiB,GAAG,cAAc,CAA0B,mBAAmB,EAAE;IACrF,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,oBAAoB,EAAE,CAAC;CACrE,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { MockLocationCheckPlugin } from './definitions';\n\nconst MockLocationCheck = registerPlugin<MockLocationCheckPlugin>('MockLocationCheck', {\n web: () => import('./web').then((m) => new m.MockLocationCheckWeb()),\n});\n\nexport * from './definitions';\nexport { MockLocationCheck };\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { MockLocationCheckPlugin } from './definitions';
|
|
3
|
+
export declare class MockLocationCheckWeb extends WebPlugin implements MockLocationCheckPlugin {
|
|
4
|
+
isLocationMocked(): Promise<{
|
|
5
|
+
isLocationMocked: boolean;
|
|
6
|
+
}>;
|
|
7
|
+
}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
export class MockLocationCheckWeb extends WebPlugin {
|
|
3
|
+
async isLocationMocked() {
|
|
4
|
+
console.log('isLocationMocked', 'MockLocationCheck is not supported on the web');
|
|
5
|
+
return {
|
|
6
|
+
isLocationMocked: false
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAI1C,MAAM,OAAO,oBAAqB,SAAQ,SAAS;IACjD,KAAK,CAAC,gBAAgB;QACpB,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,+CAA+C,CAAC,CAAC;QACjF,OAAO;YACL,gBAAgB,EAAE,KAAK;SACxB,CAAC;IACJ,CAAC;CACF","sourcesContent":["import {WebPlugin} from '@capacitor/core';\n\nimport type {MockLocationCheckPlugin} from './definitions';\n\nexport class MockLocationCheckWeb extends WebPlugin implements MockLocationCheckPlugin {\n async isLocationMocked(): Promise<{ isLocationMocked: boolean }> {\n console.log('isLocationMocked', 'MockLocationCheck is not supported on the web');\n return {\n isLocationMocked: false\n };\n }\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@capacitor/core');
|
|
4
|
+
|
|
5
|
+
const MockLocationCheck = core.registerPlugin('MockLocationCheck', {
|
|
6
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.MockLocationCheckWeb()),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
class MockLocationCheckWeb extends core.WebPlugin {
|
|
10
|
+
async isLocationMocked() {
|
|
11
|
+
console.log('isLocationMocked', 'MockLocationCheck is not supported on the web');
|
|
12
|
+
return {
|
|
13
|
+
isLocationMocked: false
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
19
|
+
__proto__: null,
|
|
20
|
+
MockLocationCheckWeb: MockLocationCheckWeb
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
exports.MockLocationCheck = MockLocationCheck;
|
|
24
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst MockLocationCheck = registerPlugin('MockLocationCheck', {\n web: () => import('./web').then((m) => new m.MockLocationCheckWeb()),\n});\nexport * from './definitions';\nexport { MockLocationCheck };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class MockLocationCheckWeb extends WebPlugin {\n async isLocationMocked() {\n console.log('isLocationMocked', 'MockLocationCheck is not supported on the web');\n return {\n isLocationMocked: false\n };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,iBAAiB,GAAGA,mBAAc,CAAC,mBAAmB,EAAE;AAC9D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,oBAAoB,EAAE,CAAC;AACxE,CAAC;;ACFM,MAAM,oBAAoB,SAASC,cAAS,CAAC;AACpD,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,+CAA+C,CAAC;AACxF,QAAQ,OAAO;AACf,YAAY,gBAAgB,EAAE;AAC9B,SAAS;AACT;AACA;;;;;;;;;"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var capacitorMockLocationCheck = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const MockLocationCheck = core.registerPlugin('MockLocationCheck', {
|
|
5
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.MockLocationCheckWeb()),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
class MockLocationCheckWeb extends core.WebPlugin {
|
|
9
|
+
async isLocationMocked() {
|
|
10
|
+
console.log('isLocationMocked', 'MockLocationCheck is not supported on the web');
|
|
11
|
+
return {
|
|
12
|
+
isLocationMocked: false
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
18
|
+
__proto__: null,
|
|
19
|
+
MockLocationCheckWeb: MockLocationCheckWeb
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
exports.MockLocationCheck = MockLocationCheck;
|
|
23
|
+
|
|
24
|
+
return exports;
|
|
25
|
+
|
|
26
|
+
})({}, capacitorExports);
|
|
27
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst MockLocationCheck = registerPlugin('MockLocationCheck', {\n web: () => import('./web').then((m) => new m.MockLocationCheckWeb()),\n});\nexport * from './definitions';\nexport { MockLocationCheck };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class MockLocationCheckWeb extends WebPlugin {\n async isLocationMocked() {\n console.log('isLocationMocked', 'MockLocationCheck is not supported on the web');\n return {\n isLocationMocked: false\n };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,iBAAiB,GAAGA,mBAAc,CAAC,mBAAmB,EAAE;IAC9D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,oBAAoB,EAAE,CAAC;IACxE,CAAC;;ICFM,MAAM,oBAAoB,SAASC,cAAS,CAAC;IACpD,IAAI,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,+CAA+C,CAAC;IACxF,QAAQ,OAAO;IACf,YAAY,gBAAgB,EAAE;IAC9B,SAAS;IACT;IACA;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import Capacitor
|
|
2
|
+
import CoreLocation
|
|
3
|
+
import Foundation
|
|
4
|
+
|
|
5
|
+
/// Please read the Capacitor iOS Plugin Development Guide
|
|
6
|
+
/// here: https://capacitorjs.com/docs/plugins/ios
|
|
7
|
+
@objc(MockLocationCheckPlugin)
|
|
8
|
+
public class MockLocationCheckPlugin: CAPPlugin, CAPBridgedPlugin, CLLocationManagerDelegate {
|
|
9
|
+
public let identifier = "MockLocationCheckPlugin"
|
|
10
|
+
public let jsName = "MockLocationCheck"
|
|
11
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
12
|
+
CAPPluginMethod(name: "isLocationMocked", returnType: CAPPluginReturnPromise)
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
private var locationManager: CLLocationManager!
|
|
16
|
+
private var call: CAPPluginCall?
|
|
17
|
+
|
|
18
|
+
@objc func isLocationMocked(_ call: CAPPluginCall) {
|
|
19
|
+
self.call = call
|
|
20
|
+
|
|
21
|
+
DispatchQueue.main.async {
|
|
22
|
+
self.locationManager = CLLocationManager()
|
|
23
|
+
self.locationManager.delegate = self
|
|
24
|
+
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
|
|
25
|
+
|
|
26
|
+
let status = CLLocationManager.authorizationStatus()
|
|
27
|
+
if status == .notDetermined {
|
|
28
|
+
self.locationManager.requestWhenInUseAuthorization()
|
|
29
|
+
} else if status == .authorizedWhenInUse || status == .authorizedAlways {
|
|
30
|
+
self.locationManager.requestLocation()
|
|
31
|
+
} else {
|
|
32
|
+
call.reject("Location permissions not granted.")
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public func locationManager(
|
|
38
|
+
_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]
|
|
39
|
+
) {
|
|
40
|
+
guard let location = locations.last else {
|
|
41
|
+
call?.reject("Unable to obtain location.")
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
let isSimulated = location.sourceInformation!.isSimulatedBySoftware
|
|
45
|
+
let result = ["isLocationMocked": isSimulated]
|
|
46
|
+
call?.resolve(result)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
|
|
50
|
+
call?.reject("Location error: \(error.localizedDescription)")
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public func locationManager(
|
|
54
|
+
_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus
|
|
55
|
+
) {
|
|
56
|
+
if status == .authorizedWhenInUse || status == .authorizedAlways {
|
|
57
|
+
manager.requestLocation()
|
|
58
|
+
} else if status == .denied || status == .restricted {
|
|
59
|
+
call?.reject("Location permissions not granted.")
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import XCTest
|
|
2
|
+
@testable import MockLocationCheckPlugin
|
|
3
|
+
|
|
4
|
+
class MockLocationCheckTests: XCTestCase {
|
|
5
|
+
func testEcho() {
|
|
6
|
+
// This is an example of a functional test case for a plugin.
|
|
7
|
+
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
|
8
|
+
|
|
9
|
+
let implementation = MockLocationCheck()
|
|
10
|
+
let value = "Hello, World!"
|
|
11
|
+
let result = implementation.echo(value)
|
|
12
|
+
|
|
13
|
+
XCTAssertEqual(value, result)
|
|
14
|
+
}
|
|
15
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@movsesiv/capacitor-mock-location-check",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Capacitor plugin allowing to check if location is mocked",
|
|
5
|
+
"main": "dist/plugin.cjs.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/esm/index.d.ts",
|
|
8
|
+
"unpkg": "dist/plugin.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"android/src/main/",
|
|
11
|
+
"android/build.gradle",
|
|
12
|
+
"dist/",
|
|
13
|
+
"ios/Sources",
|
|
14
|
+
"ios/Tests",
|
|
15
|
+
"Package.swift",
|
|
16
|
+
"CapacitorMockLocationCheck.podspec"
|
|
17
|
+
],
|
|
18
|
+
"author": "movsesiv",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/movsesiv/capacitor-mock-location-check.git"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/movsesiv/capacitor-mock-location-check/issues"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"capacitor",
|
|
29
|
+
"plugin",
|
|
30
|
+
"native"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
34
|
+
"verify:ios": "xcodebuild -scheme CapacitorMockLocationCheck -destination generic/platform=iOS",
|
|
35
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
36
|
+
"verify:web": "npm run build",
|
|
37
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
38
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
39
|
+
"eslint": "eslint . --ext ts",
|
|
40
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
|
|
41
|
+
"swiftlint": "node-swiftlint",
|
|
42
|
+
"docgen": "docgen --api MockLocationCheckPlugin --output-readme README.md --output-json dist/docs.json",
|
|
43
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
44
|
+
"clean": "rimraf ./dist",
|
|
45
|
+
"watch": "tsc --watch",
|
|
46
|
+
"prepublishOnly": "npm run build"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@capacitor/android": "^6.0.0",
|
|
50
|
+
"@capacitor/core": "^6.0.0",
|
|
51
|
+
"@capacitor/docgen": "^0.2.2",
|
|
52
|
+
"@capacitor/ios": "^6.0.0",
|
|
53
|
+
"@ionic/eslint-config": "^0.4.0",
|
|
54
|
+
"@ionic/prettier-config": "^4.0.0",
|
|
55
|
+
"@ionic/swiftlint-config": "^2.0.0",
|
|
56
|
+
"eslint": "^8.57.0",
|
|
57
|
+
"prettier": "^3.3.3",
|
|
58
|
+
"prettier-plugin-java": "^2.6.4",
|
|
59
|
+
"rimraf": "^6.0.1",
|
|
60
|
+
"rollup": "^4.24.0",
|
|
61
|
+
"swiftlint": "^2.0.0",
|
|
62
|
+
"typescript": "~4.1.5"
|
|
63
|
+
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"@capacitor/core": "^6.0.0"
|
|
66
|
+
},
|
|
67
|
+
"prettier": "@ionic/prettier-config",
|
|
68
|
+
"swiftlint": "@ionic/swiftlint-config",
|
|
69
|
+
"eslintConfig": {
|
|
70
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
71
|
+
},
|
|
72
|
+
"capacitor": {
|
|
73
|
+
"ios": {
|
|
74
|
+
"src": "ios"
|
|
75
|
+
},
|
|
76
|
+
"android": {
|
|
77
|
+
"src": "android"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|