Skip to content

Commit d96f6c4

Browse files
author
hakonk
committed
kaizen: add swift section in readme
1 parent 7d379d9 commit d96f6c4

File tree

1 file changed

+13
-41
lines changed

1 file changed

+13
-41
lines changed

README.md

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -288,50 +288,22 @@ instruction). Thus, implement the following method from `UIApplicationDelegate`
288288

289289
#### Integration of the library with a Swift iOS project
290290

291-
Until a better solution is available, we must use `react-native-app-auth` as a Static Library. This is due to the fact that the library is calling `AppDelegate.swift`.
292-
293-
1. Unlink `react-native-app-auth` from your projects `Libraries/`.
294-
295-
2. Manually copy the `RNAppAuth.h` and `RNAppAuth.m` files from the library folder in your `node_modules/` into your project folder.
296-
297-
3. In `RNAppAuth.m` add a new import:
298-
```Objective-C
299-
#import "<YouProjectName>-Swift.h"
300-
```
301-
302-
4. In your project's `AppDelegate.swift`, expose your function to `Objective-C` by annotating the AppDelegate with:
303-
```Swift
304-
@objc(AppDelegate)
305-
```
306-
307-
5. Add the following code just after the class declaration:
308-
```Swift
309-
var currentAuthorizationFlow: OIDAuthorizationFlowSession?
310-
```
311-
312-
6. At the bottom of your class add the following code:
313-
314-
```Swift
315-
func application(
291+
The approach mentioned above should also be possible to employ with Swift. In this case one shoule have to import `RNAppAuth`
292+
and make `AppDelegate` conform to `RNAppAuthAuthorizationFlowManager`. `AppDelegate` should look something like this:
293+
294+
```swift
295+
@import RNAppAuth
296+
class AppDelegate: UIApplicationDelegate, RNAppAuthAuthorizationFlowManager {
297+
private var currentAuthorizationFlow: OIDAuthorizationFlowSession?
298+
func application(
316299
_ app: UIApplication,
317300
open url: URL,
318301
options: [UIApplicationOpenURLOptionsKey: Any] = [:]) -> Bool {
319-
320-
if currentAuthorizationFlow!.resumeAuthorizationFlow(with: url){
321-
currentAuthorizationFlow = nil
322-
return true
323-
}
324-
325-
return false;
326-
}
327-
```
328-
This is a translation of the following `Objective-C` code provided [above](#add-a-current-authorization-session)
329-
330-
**Warning:**
331-
332-
You may need to perform Step 4 and compile your project so that the hidden bridging header file is created. If this file is not created and you follow the rest of the steps then you may fall into a chicken before the egg problem where the project is failing to build because of the missing header file and the header file won't be created because the build is failing.
333-
334-
302+
defer { currentAuthorizationFlow = nil }
303+
return currentAuthorizationFlow?.resumeAuthorizationFlow(with: url) ?? false
304+
}
305+
}
306+
```
335307

336308
### Android Setup
337309

0 commit comments

Comments
 (0)