Skip to content
This repository was archived by the owner on May 20, 2022. It is now read-only.

Commit eb2de18

Browse files
committed
fix(expo): improve expo plugin
1 parent 83c7b8f commit eb2de18

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

example/ios/example/AppDelegate.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ static void InitializeFlipper(UIApplication *application) {
2828
@implementation AppDelegate
2929

3030
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
31-
return [MSALPublicClientApplication handleMSALResponse:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]] || [RCTLinkingManager application:application openURL:url options:options];
31+
if ([MSALPublicClientApplication handleMSALResponse:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]]) {
32+
return true;
33+
}
34+
return [RCTLinkingManager application:application openURL:url options:options];
3235
}
3336

3437
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

plugin/build/withIosReactNativeMSAL.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ function setAppDelegate(appDelegate) {
3838
const [firstLine, ...restOfLines] = appDelegate.split('\n');
3939
appDelegate = firstLine + '\n\n#import <MSAL/MSAL.h>\n' + restOfLines.join('\n');
4040
}
41-
const linkingMethod = `- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
42-
return [MSALPublicClientApplication handleMSALResponse:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]] || [RCTLinkingManager application:application openURL:url options:options];
43-
}`;
44-
const linkingMethodRegex = /- \(BOOL\)application:\(UIApplication \*\)application\s+openURL:\(NSURL \*\)url\s+options:\(NSDictionary<UIApplicationOpenURLOptionsKey,id> \*\)options\s*{.+?}/s;
45-
if (linkingMethodRegex.test(appDelegate)) {
46-
appDelegate = appDelegate.replace(linkingMethodRegex, linkingMethod);
47-
}
48-
else {
49-
appDelegate = appDelegate.replace('@implementation AppDelegate', `@implementation AppDelegate\n\n${linkingMethod}`);
41+
const msalHandleResponseMethod = '[MSALPublicClientApplication handleMSALResponse:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]]';
42+
if (appDelegate.includes(msalHandleResponseMethod)) {
43+
return appDelegate;
5044
}
45+
const linkingMethodReturn = 'return [RCTLinkingManager application:application openURL:url options:options];';
46+
const newReturn = `if ([MSALPublicClientApplication handleMSALResponse:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]]) {
47+
return true;
48+
}
49+
${linkingMethodReturn}`;
50+
appDelegate = appDelegate.replace(linkingMethodReturn, newReturn);
5151
return appDelegate;
5252
}
5353
const withIosReactNativeMSAL = (config) => {

plugin/src/withIosReactNativeMSAL.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,19 @@ function setAppDelegate(appDelegate: string) {
4040
appDelegate = firstLine + '\n\n#import <MSAL/MSAL.h>\n' + restOfLines.join('\n');
4141
}
4242

43-
const linkingMethod = `- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
44-
return [MSALPublicClientApplication handleMSALResponse:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]] || [RCTLinkingManager application:application openURL:url options:options];
45-
}`;
46-
const linkingMethodRegex =
47-
/- \(BOOL\)application:\(UIApplication \*\)application\s+openURL:\(NSURL \*\)url\s+options:\(NSDictionary<UIApplicationOpenURLOptionsKey,id> \*\)options\s*{.+?}/s;
48-
49-
if (linkingMethodRegex.test(appDelegate)) {
50-
appDelegate = appDelegate.replace(linkingMethodRegex, linkingMethod);
51-
} else {
52-
appDelegate = appDelegate.replace('@implementation AppDelegate', `@implementation AppDelegate\n\n${linkingMethod}`);
43+
const msalHandleResponseMethod =
44+
'[MSALPublicClientApplication handleMSALResponse:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]]';
45+
46+
if (appDelegate.includes(msalHandleResponseMethod)) {
47+
return appDelegate;
48+
}
49+
50+
const linkingMethodReturn = 'return [RCTLinkingManager application:application openURL:url options:options];';
51+
const newReturn = `if ([MSALPublicClientApplication handleMSALResponse:url sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]]) {
52+
return true;
5353
}
54+
${linkingMethodReturn}`;
55+
appDelegate = appDelegate.replace(linkingMethodReturn, newReturn);
5456
return appDelegate;
5557
}
5658

0 commit comments

Comments
 (0)