Skip to content

Commit

Permalink
Deprecate FBSDKLoginBehaviorNative
Browse files Browse the repository at this point in the history
Summary: Deprecate FBSDKLoginBehaviorNative option (note that it currently does the exact same thing as FBSDKLoginBehaviorBrowser anyway)

Reviewed By: dreamolight

Differential Revision: D14690445

fbshipit-source-id: 97c615205083fc243a207e62c4750828d67f4e84
  • Loading branch information
robtimp authored and facebook-github-bot committed Mar 29, 2019
1 parent c6a2a1b commit 95e67c9
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 98 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Deprecated

- `FBSDKLoginBehaviorNative`
- `FBSDKLoginBehaviorSystemAccount`
- `FBSDKLoginBehaviorWeb`
- `[FBSDKLoginManager renewSystemCredentials]`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ NS_ASSUME_NONNULL_BEGIN
Note that Facebook recovery attempters can present UI or even cause app switches (such as to login). Any such
work is dispatched to the main thread (therefore your request handlers may then run on the main thread).
Login recovery requires FBSDKLoginKit. Login will use FBSDKLoginBehaviorNative and will prompt the user
Login recovery requires FBSDKLoginKit. Login will prompt the user
for all permissions last granted. If any are declined on the new request, the recovery is not successful but
the `[FBSDKAccessToken currentAccessToken]` might still have been updated.
.
Expand Down
11 changes: 4 additions & 7 deletions FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,11 @@ typedef NS_ENUM(NSUInteger, FBSDKDefaultAudience)
typedef NS_ENUM(NSUInteger, FBSDKLoginBehavior)
{
/**
This is the default behavior, and indicates logging in through the native
Facebook app may be used. The SDK may still use Safari instead.
This is the default behavior, and indicates logging in via ASWebAuthenticationSession (iOS 12+) or SFAuthenticationSession (iOS 11),
which present specialized SafariViewControllers. Falls back to plain SFSafariViewController (iOS 9 and 10) or Safari (iOS 8).
*/
FBSDKLoginBehaviorNative = 0,
/**
Attempts log in through the Safari or SFSafariViewController, if available.
*/
FBSDKLoginBehaviorBrowser,
FBSDKLoginBehaviorBrowser = 0,
FBSDKLoginBehaviorNative __deprecated_enum_msg("Use FBSDKLoginBehaviorBrowser.") = FBSDKLoginBehaviorBrowser,
FBSDKLoginBehaviorSystemAccount __deprecated_enum_msg("Use FBSDKLoginBehaviorBrowser.") = FBSDKLoginBehaviorBrowser,
FBSDKLoginBehaviorWeb __deprecated_enum_msg("Use FBSDKLoginBehaviorBrowser.") = FBSDKLoginBehaviorBrowser,
} NS_SWIFT_NAME(LoginBehavior);
Expand Down
64 changes: 6 additions & 58 deletions FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -412,38 +412,11 @@ - (void)logInWithBehavior:(FBSDKLoginBehavior)loginBehavior
}
};

switch (loginBehavior) {
case FBSDKLoginBehaviorNative: {
if ([FBSDKInternalUtility isFacebookAppInstalled]) {
BOOL useNativeDialog = [serverConfiguration useNativeDialogForDialogName:FBSDKDialogConfigurationNameLogin];
if (useNativeDialog) {
[self performNativeLogInWithParameters:loginParams handler:^(BOOL openedURL, NSError *openedURLError) {
if (openedURLError) {
[FBSDKLogger singleShotLogEntry:FBSDKLoggingBehaviorDeveloperErrors
formatString:@"FBSDKLoginBehaviorNative failed : %@\nTrying FBSDKLoginBehaviorBrowser", openedURLError];
}
if (openedURL) {
completion(YES, FBSDKLoginManagerLoggerAuthMethod_Native, openedURLError);
} else {
[self logInWithBehavior:FBSDKLoginBehaviorBrowser];
}
}];
} else {
[self logInWithBehavior:FBSDKLoginBehaviorBrowser];
}
break;
}
// Intentional fall through. Switching to browser login instead.
}
case FBSDKLoginBehaviorBrowser: {
[self performBrowserLogInWithParameters:loginParams handler:^(BOOL openedURL,
NSString *authMethod,
NSError *openedURLError) {
completion(openedURL, authMethod, openedURLError);
}];
break;
}
}
[self performBrowserLogInWithParameters:loginParams handler:^(BOOL openedURL,
NSString *authMethod,
NSError *openedURLError) {
completion(openedURL, authMethod, openedURLError);
}];
}

- (void)storeExpectedChallenge:(NSString *)challengeExpected
Expand Down Expand Up @@ -494,32 +467,6 @@ - (void)setRequestedPermissions:(NSSet *)requestedPermissions
_requestedPermissions = [requestedPermissions copy];
}

@end

#pragma mark -

@implementation FBSDKLoginManager (Native)

- (void)performNativeLogInWithParameters:(NSDictionary *)loginParams handler:(void(^)(BOOL, NSError*))handler
{
[_logger willAttemptAppSwitchingBehavior];
loginParams = [_logger parametersWithTimeStampAndClientState:loginParams forAuthMethod:FBSDKLoginManagerLoggerAuthMethod_Native];

NSString *scheme = ([FBSDKSettings appURLSchemeSuffix] ? @"fbauth2" : @"fbauth");
NSMutableDictionary *mutableParams = [NSMutableDictionary dictionaryWithDictionary:loginParams];
mutableParams[@"legacy_override"] = FBSDK_TARGET_PLATFORM_VERSION;
NSError *error;
NSURL *authURL = [FBSDKInternalUtility URLWithScheme:scheme host:@"authorize" path:@"" queryParameters:mutableParams error:&error];

NSDate *start = [NSDate date];
[[FBSDKBridgeAPI sharedInstance] openURL:authURL sender:self handler:^(BOOL openedURL, NSError *anError) {
[self->_logger logNativeAppDialogResult:openedURL dialogDuration:-start.timeIntervalSinceNow];
if (handler) {
handler(openedURL, anError);
}
}];
}

// change bool to auth method string.
- (void)performBrowserLogInWithParameters:(NSDictionary *)loginParams
handler:(FBSDKBrowserLoginSuccessBlock)handler
Expand Down Expand Up @@ -570,6 +517,7 @@ - (void)performBrowserLogInWithParameters:(NSDictionary *)loginParams
}
}

#pragma mark - FBSDKURLOpening
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
BOOL isFacebookURL = [self canOpenURL:url forApplication:application sourceApplication:sourceApplication annotation:annotation];
Expand Down
18 changes: 0 additions & 18 deletions FBSDKLoginKit/FBSDKLoginKit/Internal/FBSDKLoginCompletion.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,24 +127,6 @@ - (instancetype)initWithURLParameters:(NSDictionary *)parameters appID:(NSString

- (void)completeLogIn:(FBSDKLoginManager *)loginManager withHandler:(FBSDKLoginCompletionParametersBlock)handler
{
if (_performExplicitFallback && loginManager.loginBehavior == FBSDKLoginBehaviorNative) {
// UIKit and iOS don't like an application opening a URL during a URL open callback, so
// we need to wait until *at least* the next turn of the run loop to open the URL to
// perform the browser log in behavior. However we also need to wait for the application
// to become active so FBSDKApplicationDelegate doesn't erroneously call back the URL
// opener before the URL has been opened.
if ([FBSDKBridgeAPI sharedInstance].isActive) {
// The application is active so there's no need to wait.
[loginManager logInWithBehavior:FBSDKLoginBehaviorBrowser];
} else {
// use the block version to guarantee there's a strong reference to self
_observer = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^ (NSNotification *notification) {
[self attemptBrowserLogIn:loginManager];
}];
}
return;
}

if (_parameters.accessTokenString && !_parameters.userID) {
void(^handlerCopy)(FBSDKLoginCompletionParameters *) = [handler copy];
FBSDKLoginRequestMeAndPermissions(_parameters, ^{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
typedef void (^FBSDKBrowserLoginSuccessBlock)(BOOL didOpen, NSString *authMethod, NSError *error)
NS_SWIFT_NAME(BrowserLoginSuccessBlock);

@interface FBSDKLoginManager ()
@interface FBSDKLoginManager () <FBSDKURLOpening>
@property (nonatomic, weak) UIViewController *fromViewController;
@property (nonatomic, readonly) NSSet *requestedPermissions;

Expand All @@ -53,13 +53,7 @@ NS_SWIFT_NAME(BrowserLoginSuccessBlock);
- (void)setHandler:(FBSDKLoginManagerLoginResultBlock)handler;
// for testing only
- (void)setRequestedPermissions:(NSSet *)requestedPermissions;

@end

// the category is made available for testing only
@interface FBSDKLoginManager (Native) <FBSDKURLOpening>

- (void)performNativeLogInWithParameters:(NSDictionary *)loginParams handler:(FBSDKSuccessBlock)handler;
// for testing only
- (void)performBrowserLogInWithParameters:(NSDictionary *)loginParams handler:(FBSDKBrowserLoginSuccessBlock)handler;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@ - (void)startSessionForLoginManager:(FBSDKLoginManager *)loginManager
NSString *behaviorString = nil;

switch (loginManager.loginBehavior) {
case FBSDKLoginBehaviorNative:
willTryNative = YES;
willTryBrowser = YES;
behaviorString = @"FBSDKLoginBehaviorNative";
break;
case FBSDKLoginBehaviorBrowser:
willTryBrowser = YES;
behaviorString = @"FBSDKLoginBehaviorBrowser";
Expand Down
2 changes: 1 addition & 1 deletion FBSDKLoginKit/FBSDKLoginKitTests/FBSDKLoginManagerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ - (void)testCallingLoginWhileAnotherLoginHasNotFinishedNoOps
FBSDKLoginManager *manager = [OCMockObject partialMockForObject:[FBSDKLoginManager new]];
[[[(id)manager stub] andDo:^(NSInvocation *invocation) {
loginCount++;
}] logInWithBehavior:FBSDKLoginBehaviorNative];
}] logInWithBehavior:FBSDKLoginBehaviorBrowser];
[manager logInWithReadPermissions:@[@"public_profile"] fromViewController:nil handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
// This will never be called
XCTFail(@"Should not be called");
Expand Down

1 comment on commit 95e67c9

@iwming
Copy link

@iwming iwming commented on 95e67c9 Oct 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why deprecate FBSDKLoginBehaviorNative?

Please sign in to comment.