Skip to content

Commit 7964db1

Browse files
Fix ios postlink (#1482)
1 parent d34a4db commit 7964db1

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

scripts/postlink/ios/postlink.js

+25-13
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,37 @@ module.exports = () => {
4040
}
4141

4242
// 2. Modify jsCodeLocation value assignment
43-
var jsCodeLocations = appDelegateContents.match(/(jsCodeLocation = .*)/);
44-
var oldJsCodeLocationAssignmentStatement;
45-
if (jsCodeLocations) {
46-
oldJsCodeLocationAssignmentStatement = jsCodeLocations[1];
47-
} else {
43+
var jsCodeLocations = appDelegateContents.match(/(jsCodeLocation = .*)/g);
44+
45+
if (!jsCodeLocations) {
4846
console.log('Couldn\'t find jsCodeLocation setting in AppDelegate.');
4947
}
5048
var newJsCodeLocationAssignmentStatement = "jsCodeLocation = [CodePush bundleURL];";
5149
if (~appDelegateContents.indexOf(newJsCodeLocationAssignmentStatement)) {
5250
console.log(`"jsCodeLocation" already pointing to "[CodePush bundleURL]".`);
5351
} else {
54-
var jsCodeLocationPatch = `
55-
#ifdef DEBUG
56-
${oldJsCodeLocationAssignmentStatement}
57-
#else
58-
${newJsCodeLocationAssignmentStatement}
59-
#endif`;
60-
appDelegateContents = appDelegateContents.replace(oldJsCodeLocationAssignmentStatement,
61-
jsCodeLocationPatch);
52+
if (jsCodeLocations.length === 1) {
53+
// If there is one `jsCodeLocation` it means that react-native app version is lower than 0.57.8
54+
// and we should replace this line with DEBUG ifdef statement and add CodePush call for Release case
55+
56+
var oldJsCodeLocationAssignmentStatement = jsCodeLocations[0];
57+
var jsCodeLocationPatch = `
58+
#ifdef DEBUG
59+
${oldJsCodeLocationAssignmentStatement}
60+
#else
61+
${newJsCodeLocationAssignmentStatement}
62+
#endif`;
63+
appDelegateContents = appDelegateContents.replace(oldJsCodeLocationAssignmentStatement,
64+
jsCodeLocationPatch);
65+
} else if (jsCodeLocations.length === 2) {
66+
// If there are two `jsCodeLocation` it means that react-native app version is higher than 0.57.8 or equal
67+
// and we should replace the second one(Release case) with CodePush call
68+
69+
appDelegateContents = appDelegateContents.replace(jsCodeLocations[1],
70+
newJsCodeLocationAssignmentStatement);
71+
} else {
72+
console.log(`AppDelegate isn't compatible for linking`);
73+
}
6274
}
6375

6476
var plistPath = getPlistPath();

0 commit comments

Comments
 (0)