expo-beacon 0.9.1 → 0.9.2
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/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withBeaconIOS.d.ts","sourceRoot":"","sources":["../src/withBeaconIOS.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAKb,MAAM,sBAAsB,CAAC;AAM9B,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;;;;;;;;;;;;OAcG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAIF,wBAAgB,iBAAiB,IAAI,MAAM,
|
|
1
|
+
{"version":3,"file":"withBeaconIOS.d.ts","sourceRoot":"","sources":["../src/withBeaconIOS.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAKb,MAAM,sBAAsB,CAAC;AAM9B,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;;;;;;;;;;;;OAcG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAIF,wBAAgB,iBAAiB,IAAI,MAAM,CA4C1C;AAuFD,QAAA,MAAM,aAAa,EAAE,YAAY,CAAC,oBAAoB,GAAG,IAAI,CAuF5D,CAAC;AA6CF,eAAe,aAAa,CAAC"}
|
|
@@ -11,52 +11,62 @@ import ExpoBeacon
|
|
|
11
11
|
import TSLocationManager
|
|
12
12
|
|
|
13
13
|
final class BeaconGeoPlugin: BeaconLifecycleDelegate {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
14
|
+
private func startTracking() {
|
|
15
|
+
BackgroundGeolocation.sharedInstance().start()
|
|
16
|
+
BackgroundGeolocation.sharedInstance().changePace(true)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
private func stopTracking() {
|
|
20
|
+
BackgroundGeolocation.sharedInstance().changePace(false)
|
|
21
|
+
BackgroundGeolocation.sharedInstance().stop()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
func beaconDidEnter(identifier: String, uuid: String, major: Int, minor: Int, distance: Double) {
|
|
25
|
+
startTracking()
|
|
26
|
+
}
|
|
27
|
+
func beaconDidExit(identifier: String, uuid: String, major: Int, minor: Int, distance: Double) {
|
|
28
|
+
stopTracking()
|
|
29
|
+
}
|
|
30
|
+
func beaconDidTimeout(identifier: String, uuid: String, major: Int, minor: Int, distance: Double) {
|
|
31
|
+
stopTracking()
|
|
32
|
+
}
|
|
33
|
+
func eddystoneDidEnter(identifier: String, namespace: String, instance: String, distance: Double) {
|
|
34
|
+
startTracking()
|
|
35
|
+
}
|
|
36
|
+
func eddystoneDidExit(identifier: String, namespace: String, instance: String, distance: Double) {
|
|
37
|
+
stopTracking()
|
|
38
|
+
}
|
|
39
|
+
func eddystoneDidTimeout(identifier: String, namespace: String, instance: String, distance: Double) {
|
|
40
|
+
stopTracking()
|
|
41
|
+
}
|
|
42
|
+
// Start tracking when the device connects to CarPlay (wired or wireless),
|
|
43
|
+
// stop when it disconnects.
|
|
44
|
+
func carPlayDidConnect(transport: String) {
|
|
45
|
+
startTracking()
|
|
46
|
+
}
|
|
47
|
+
func carPlayDidDisconnect() {
|
|
48
|
+
stopTracking()
|
|
49
|
+
}
|
|
40
50
|
}
|
|
41
51
|
`;
|
|
42
52
|
}
|
|
43
53
|
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
44
54
|
function modifyAppDelegateSwift(contents) {
|
|
45
|
-
const importLine =
|
|
55
|
+
const importLine = "import ExpoBeacon";
|
|
46
56
|
// 1. Add import after the last existing import line.
|
|
47
57
|
if (!contents.includes(importLine)) {
|
|
48
|
-
const lines = contents.split(
|
|
49
|
-
const lastImportIdx = lines.reduce((last, line, i) => (line.trimStart().startsWith(
|
|
58
|
+
const lines = contents.split("\n");
|
|
59
|
+
const lastImportIdx = lines.reduce((last, line, i) => (line.trimStart().startsWith("import ") ? i : last), -1);
|
|
50
60
|
if (lastImportIdx >= 0) {
|
|
51
61
|
lines.splice(lastImportIdx + 1, 0, importLine);
|
|
52
62
|
}
|
|
53
63
|
else {
|
|
54
|
-
lines.splice(0, 0, importLine,
|
|
64
|
+
lines.splice(0, 0, importLine, "");
|
|
55
65
|
}
|
|
56
|
-
contents = lines.join(
|
|
66
|
+
contents = lines.join("\n");
|
|
57
67
|
}
|
|
58
68
|
// 2. Insert registration call before `return super.application(…didFinishLaunchingWithOptions…)`.
|
|
59
|
-
const registrationCall =
|
|
69
|
+
const registrationCall = "BeaconLifecycleRegistry.register(BeaconGeoPlugin())";
|
|
60
70
|
if (contents.includes(registrationCall)) {
|
|
61
71
|
return contents; // already patched
|
|
62
72
|
}
|
|
@@ -72,9 +82,12 @@ function modifyAppDelegateSwift(contents) {
|
|
|
72
82
|
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
|
|
73
83
|
}
|
|
74
84
|
`;
|
|
75
|
-
const lastBraceIdx = contents.lastIndexOf(
|
|
85
|
+
const lastBraceIdx = contents.lastIndexOf("}");
|
|
76
86
|
if (lastBraceIdx >= 0) {
|
|
77
|
-
contents =
|
|
87
|
+
contents =
|
|
88
|
+
contents.slice(0, lastBraceIdx) +
|
|
89
|
+
methodOverride +
|
|
90
|
+
contents.slice(lastBraceIdx);
|
|
78
91
|
}
|
|
79
92
|
return contents;
|
|
80
93
|
}
|
|
@@ -96,7 +109,7 @@ function findAppDir(platformRoot) {
|
|
|
96
109
|
catch {
|
|
97
110
|
continue;
|
|
98
111
|
}
|
|
99
|
-
const swiftPath = path.join(dirPath,
|
|
112
|
+
const swiftPath = path.join(dirPath, "AppDelegate.swift");
|
|
100
113
|
if (fs.existsSync(swiftPath)) {
|
|
101
114
|
return { appDir: entry, appDelegatePath: swiftPath };
|
|
102
115
|
}
|
|
@@ -108,15 +121,15 @@ const withBeaconIOS = (config, props) => {
|
|
|
108
121
|
const opts = props !== null && props !== void 0 ? props : {};
|
|
109
122
|
// Step 1 – write BeaconGeoPlugin.swift into the iOS app directory.
|
|
110
123
|
config = (0, config_plugins_1.withDangerousMod)(config, [
|
|
111
|
-
|
|
124
|
+
"ios",
|
|
112
125
|
(config) => {
|
|
113
126
|
const platformRoot = config.modRequest.platformProjectRoot;
|
|
114
127
|
const result = findAppDir(platformRoot);
|
|
115
128
|
if (!result) {
|
|
116
|
-
console.warn(
|
|
129
|
+
console.warn("[expo-beacon] Could not locate iOS app directory — BeaconGeoPlugin.swift was not written.");
|
|
117
130
|
return config;
|
|
118
131
|
}
|
|
119
|
-
const outputPath = path.join(platformRoot, result.appDir,
|
|
132
|
+
const outputPath = path.join(platformRoot, result.appDir, "BeaconGeoPlugin.swift");
|
|
120
133
|
fs.writeFileSync(outputPath, getIOSPluginSwift());
|
|
121
134
|
return config;
|
|
122
135
|
},
|
|
@@ -128,10 +141,10 @@ const withBeaconIOS = (config, props) => {
|
|
|
128
141
|
const filePath = `${projectName}/BeaconGeoPlugin.swift`;
|
|
129
142
|
if (!xcodeProject.hasFile(filePath)) {
|
|
130
143
|
// pbxGroupByName returns the group object; addSourceFile needs the UUID key.
|
|
131
|
-
const groups = xcodeProject.hash.project.objects[
|
|
144
|
+
const groups = xcodeProject.hash.project.objects["PBXGroup"];
|
|
132
145
|
let groupKey;
|
|
133
146
|
for (const key of Object.keys(groups)) {
|
|
134
|
-
if (key.endsWith(
|
|
147
|
+
if (key.endsWith("_comment"))
|
|
135
148
|
continue;
|
|
136
149
|
const g = groups[key];
|
|
137
150
|
if (g.name === projectName || g.path === projectName) {
|
|
@@ -145,16 +158,16 @@ const withBeaconIOS = (config, props) => {
|
|
|
145
158
|
});
|
|
146
159
|
// Step 3 – patch AppDelegate.swift to register the plugin.
|
|
147
160
|
config = (0, config_plugins_1.withDangerousMod)(config, [
|
|
148
|
-
|
|
161
|
+
"ios",
|
|
149
162
|
(config) => {
|
|
150
163
|
const platformRoot = config.modRequest.platformProjectRoot;
|
|
151
164
|
const result = findAppDir(platformRoot);
|
|
152
165
|
if (!result) {
|
|
153
|
-
console.warn(
|
|
154
|
-
|
|
166
|
+
console.warn("[expo-beacon] AppDelegate.swift not found — " +
|
|
167
|
+
"please add BeaconLifecycleRegistry.register(BeaconGeoPlugin()) manually.");
|
|
155
168
|
return config;
|
|
156
169
|
}
|
|
157
|
-
const original = fs.readFileSync(result.appDelegatePath,
|
|
170
|
+
const original = fs.readFileSync(result.appDelegatePath, "utf-8");
|
|
158
171
|
fs.writeFileSync(result.appDelegatePath, modifyAppDelegateSwift(original));
|
|
159
172
|
return config;
|
|
160
173
|
},
|
|
@@ -166,9 +179,9 @@ const withBeaconIOS = (config, props) => {
|
|
|
166
179
|
return config;
|
|
167
180
|
};
|
|
168
181
|
// ─── CarPlay Driving Task wiring ──────────────────────────────────────────────
|
|
169
|
-
const CARPLAY_ENTITLEMENT_KEY =
|
|
170
|
-
const CARPLAY_SCENE_DELEGATE_CLASS =
|
|
171
|
-
const CARPLAY_SCENE_CONFIG_NAME =
|
|
182
|
+
const CARPLAY_ENTITLEMENT_KEY = "com.apple.developer.carplay-driving-task";
|
|
183
|
+
const CARPLAY_SCENE_DELEGATE_CLASS = "ExpoBeacon.BeaconCarPlaySceneDelegate";
|
|
184
|
+
const CARPLAY_SCENE_CONFIG_NAME = "ExpoBeaconCarPlay";
|
|
172
185
|
function withCarPlayDrivingTask(config) {
|
|
173
186
|
// 4a — entitlement
|
|
174
187
|
config = (0, config_plugins_1.withEntitlementsPlist)(config, (cfg) => {
|
|
@@ -191,7 +204,7 @@ function withCarPlayDrivingTask(config) {
|
|
|
191
204
|
(entry === null || entry === void 0 ? void 0 : entry.UISceneConfigurationName) === CARPLAY_SCENE_CONFIG_NAME);
|
|
192
205
|
if (!alreadyPresent) {
|
|
193
206
|
role.push({
|
|
194
|
-
UISceneClassName:
|
|
207
|
+
UISceneClassName: "CPTemplateApplicationScene",
|
|
195
208
|
UISceneConfigurationName: CARPLAY_SCENE_CONFIG_NAME,
|
|
196
209
|
UISceneDelegateClassName: CARPLAY_SCENE_DELEGATE_CLASS,
|
|
197
210
|
});
|