-
Notifications
You must be signed in to change notification settings - Fork 319
/
app.plugin.js
109 lines (93 loc) · 3.09 KB
/
app.plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const {
AndroidConfig,
withInfoPlist,
withEntitlementsPlist,
} = require('@expo/config-plugins');
const NFC_READER = 'Interact with nearby NFC devices';
function withIosPermission(c, props = {}) {
const {nfcPermission} = props;
return withInfoPlist(c, (config) => {
// https://developer.apple.com/documentation/bundleresources/information_property_list/nfcreaderusagedescription?language=objc
config.modResults.NFCReaderUsageDescription =
nfcPermission ||
config.modResults.NFCReaderUsageDescription ||
NFC_READER;
return config;
});
}
function addValuesToArray(obj, key, values) {
if (!Array.isArray(values) || !values.length) {
return obj;
}
if (!Array.isArray(obj[key])) {
obj[key] = [];
}
// Add the required values
obj[key].push(...values);
// Remove duplicates
obj[key] = [...new Set(obj[key])];
// Prevent adding empty arrays to Info.plist or *.entitlements
if (!obj[key].length) {
delete obj[key];
}
return obj;
}
function withIosNfcEntitlement(c, {includeNdefEntitlement}) {
return withEntitlementsPlist(c, (config) => {
// Add the required formats
let entitlements = ['NDEF', 'TAG']
if (includeNdefEntitlement === false) {
entitlements = ['TAG']
}
config.modResults = addValuesToArray(
config.modResults,
'com.apple.developer.nfc.readersession.formats',
entitlements,
);
return config;
});
}
function withIosNfcSelectIdentifiers(c, {selectIdentifiers}) {
return withInfoPlist(c, (config) => {
// Add the user defined identifiers
config.modResults = addValuesToArray(
config.modResults,
// https://developer.apple.com/documentation/bundleresources/information_property_list/select-identifiers
'com.apple.developer.nfc.readersession.iso7816.select-identifiers',
selectIdentifiers || [],
);
return config;
});
}
function withIosNfcSystemCodes(c, {systemCodes}) {
return withInfoPlist(c, (config) => {
// Add the user defined identifiers
config.modResults = addValuesToArray(
config.modResults,
// https://developer.apple.com/documentation/bundleresources/information_property_list/systemcodes
'com.apple.developer.nfc.readersession.felica.systemcodes',
systemCodes || [],
);
return config;
});
}
function withNfc(config, props = {}) {
const {nfcPermission, selectIdentifiers, systemCodes, includeNdefEntitlement} = props;
config = withIosNfcEntitlement(config, {includeNdefEntitlement});
config = withIosNfcSelectIdentifiers(config, {selectIdentifiers});
config = withIosNfcSystemCodes(config, {systemCodes});
// We start to support Android 12 from v3.11.1, and you will need to update compileSdkVersion to 31,
// otherwise the build will fail:
config = AndroidConfig.Version.withBuildScriptExtMinimumVersion(config, {
name: 'compileSdkVersion',
minVersion: 31,
});
if (nfcPermission !== false) {
config = withIosPermission(config, props);
config = AndroidConfig.Permissions.withPermissions(config, [
'android.permission.NFC',
]);
}
return config;
}
module.exports = withNfc;