Skip to content

Commit b5cd4d0

Browse files
author
hakonk
committed
chore: rewrite ios section in readme such that it covers changes
1 parent cb5061a commit b5cd4d0

File tree

1 file changed

+11
-30
lines changed

1 file changed

+11
-30
lines changed

README.md

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ AppAuth supports three options for dependency management.
210210
With [CocoaPods](https://guides.cocoapods.org/using/getting-started.html), add the following line to
211211
your `Podfile`:
212212

213-
pod 'AppAuth', '>= 0.91'
213+
pod 'AppAuth', '>= 0.94'
214214

215-
Then run `pod install`. Note that version 0.91 is the first of the library to support iOS 11.
215+
Then run `pod install`. Note that version 0.94 is the first of the library to support iOS 11.
216216

217217
2. **Carthage**
218218

@@ -264,58 +264,39 @@ authorization flow from the redirect. Follow these steps:
264264

265265
`RNAppAuth` will call on the given app's delegate via `[UIApplication sharedApplication].delegate`.
266266
Furthermore, `RNAppAuth` expects the delegate instance to conform to the protocol `RNAppAuthAuthorizationFlowManager`.
267-
Make `AppDelegate` conform to `RNAppAuthAuthorizationFlowManager`:
267+
Make `AppDelegate` conform to `RNAppAuthAuthorizationFlowManager` with the following changes to `AppDelegate.h`:
268268

269269
```diff
270-
+ // Depending on build configurations, import either with:
271-
+@import RNAppAuth;
272-
+ // or:
273-
+import <AppAuth/AppAuth.h>
274-
+import "RNAppAuthAuthorizationFlowManager.h"
275-
276-
+ @interface AppDelegate()<RNAppAuthAuthorizationFlowManager> {
277-
+ id <OIDAuthorizationFlowSession> _currentSession;
278-
+ }
279-
+ @end
280-
```
281-
282-
Implement the required method of `RNAppAuthAuthorizationFlowManager` in `AppDelegate`:
283-
284-
```diff
285-
+ -(void)setCurrentAuthorizationFlowSession:(id<OIDAuthorizationFlowSession>)session {
286-
+ // retain session for further use
287-
+ _currentSession = session;
288-
+ }
270+
+#import <RNAppAuth/RNAppAuthAuthorizationFlowManager.h>
271+
+@interface AppDelegate : UIResponder <UIApplicationDelegate, RNAppAuthAuthorizationFlowManager>
272+
+@property(nonatomic, weak)id<RNAppAuthAuthorizationFlowManagerDelegate>authorizationFlowManagerDelegate;
289273
```
290274

291275
The authorization response URL is returned to the app via the iOS openURL app delegate method, so
292276
you need to pipe this through to the current authorization session (created in the previous
293-
instruction). Thus, implement the following method from `UIApplicationDelegate` in `AppDelegate`:
277+
instruction). Thus, implement the following method from `UIApplicationDelegate` in `AppDelegate.m`:
294278

295279
```diff
296280
+ - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *, id> *)options {
297-
+ BOOL shouldOpenUrl = [_currentSession resumeAuthorizationFlowWithURL:url];
298-
+ _currentSession = nil;
299-
+ return shouldOpenUrl;
281+
+ return return [self.authorizationFlowManagerDelegate resumeExternalUserAgentFlowWithURL:url];
300282
+ }
301283
```
302284

303285
#### Integration of the library with a Swift iOS project
304286

305287
The approach mentioned above should also be possible to employ with Swift. In this case one should have to import `RNAppAuth`
306288
and make `AppDelegate` conform to `RNAppAuthAuthorizationFlowManager`. Note that this has not been tested.
307-
`AppDelegate` should look something like this:
289+
`AppDelegate.swift` should look something like this:
308290

309291
```swift
310292
@import RNAppAuth
311293
class AppDelegate: UIApplicationDelegate, RNAppAuthAuthorizationFlowManager {
312-
private var currentAuthorizationFlow: OIDAuthorizationFlowSession?
294+
public weak var authorizationFlowManagerDelegate: RNAppAuthAuthorizationFlowManagerDelegate?
313295
func application(
314296
_ app: UIApplication,
315297
open url: URL,
316298
options: [UIApplicationOpenURLOptionsKey: Any] = [:]) -> Bool {
317-
defer { currentAuthorizationFlow = nil }
318-
return currentAuthorizationFlow?.resumeAuthorizationFlow(with: url) ?? false
299+
return authorizationFlowManagerDelegate?.resumeExternalUserAgentFlowWithURL(with: url) ?? false
319300
}
320301
}
321302
```

0 commit comments

Comments
 (0)