Skip to content

Commit

Permalink
Fix strongly captured view controller being passed on login
Browse files Browse the repository at this point in the history
JIRA Issues: PUBPL-1896
  • Loading branch information
Rajul Arora committed Jul 13, 2018
1 parent e4b7a5c commit 0e5758c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions TwitterKit/TwitterKit/TWTRTwitter.m
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ - (void)logInWithViewController:(UIViewController *)viewController completion:(T
// Throws exception if the app does not have a valid scheme
[NSException raise:TWTRInvalidInitializationException format:@"Attempt made to Log in or Like a Tweet without a valid Twitter Kit URL Scheme set up in the app settings. Please see https://dev.twitter.com/twitterkit/ios/installation for more info."];
} else {
__weak typeof(viewController) weakViewController = viewController;
self.mobileSSO = [[TWTRMobileSSO alloc] initWithAuthConfig:self.sessionStore.authConfig];
[self.mobileSSO attemptAppLoginWithCompletion:^(TWTRSession *session, NSError *error) {
if (session) {
Expand All @@ -332,8 +333,9 @@ - (void)logInWithViewController:(UIViewController *)viewController completion:(T
// The user tapped "Cancel"
completion(session, error);
} else {
typeof(weakViewController) strongViewController = weakViewController;
// There wasn't a Twitter app
[self performWebBasedLogin:viewController completion:completion];
[self performWebBasedLogin:strongViewController completion:completion];
}
}
}];
Expand All @@ -350,9 +352,11 @@ - (void)performWebBasedLogin:(UIViewController *)viewController completion:(TWTR

self.webAuthenticationFlow = [[TWTRWebAuthenticationFlow alloc] initWithSessionStore:self.sessionStore];

__weak typeof(viewController) weakViewController = viewController;
[self.webAuthenticationFlow beginAuthenticationFlow:^(UIViewController *controller) {
__strong typeof(weakViewController) strongViewController = weakViewController;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
[viewController presentViewController:navigationController animated:YES completion:nil];
[strongViewController presentViewController:navigationController animated:YES completion:nil];
}
completion:^(TWTRSession *session, NSError *error) {
/**
Expand Down
11 changes: 11 additions & 0 deletions TwitterKit/TwitterKitTests/SocialTests/TwitterSocialTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,17 @@ - (void)testLoginWithViewController_performsWebBasedLoginOnError
OCMVerifyAll(mockTwitterKit);
}

- (void)testLoginWithViewController_releaseViewControllerAfterLogin
{
UIViewController *viewController = [[UIViewController alloc] init];
__weak typeof(viewController) weakViewController = viewController;
[self.twitterKit logInWithViewController:viewController
completion:^(TWTRSession *_Nullable session, NSError *_Nullable error){
}];
viewController = nil;
XCTAssertNil(weakViewController);
}

- (void)testLogout_clearsWebViewCookies
{
[self.twitterKit.sessionStore saveSession:self.session
Expand Down

0 comments on commit 0e5758c

Please sign in to comment.