Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump SDK deps to 5.5.0 and remove deprecated SDK methods and usages #169

Merged
merged 5 commits into from
Sep 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 3.0.0
* Update Android & iOS Facebook Login dependencies to `5.5`
* Removed deprecated method `loginWithPublishPermissions` and renamed `loginWithReadPermission` to `login`
* The `behavior` parameter is now ignored on iOS as it is not supported anymore by the Facebook Login SDK
* Bump iOS deployment target to `9.0`

## 2.0.1

* [#128](https://github.com/roughike/flutter_facebook_login/pull/128): Pin down FBSDKCoreKit to the same version as FBSDKLoginKit.
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ android {
}

dependencies {
api 'com.facebook.android:facebook-login:4.39.0'
api 'com.facebook.android:facebook-login:5.5.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public class FacebookLoginPlugin implements MethodCallHandler {

private static final String ERROR_UNKNOWN_LOGIN_BEHAVIOR = "unknown_login_behavior";

private static final String METHOD_LOG_IN_WITH_READ_PERMISSIONS = "loginWithReadPermissions";
private static final String METHOD_LOG_IN_WITH_PUBLISH_PERMISSIONS = "loginWithPublishPermissions";
private static final String METHOD_LOG_IN = "logIn";
private static final String METHOD_LOG_OUT = "logOut";
private static final String METHOD_GET_CURRENT_ACCESS_TOKEN = "getCurrentAccessToken";

Expand Down Expand Up @@ -50,19 +49,12 @@ public void onMethodCall(MethodCall call, Result result) {
LoginBehavior loginBehavior;

switch (call.method) {
case METHOD_LOG_IN_WITH_READ_PERMISSIONS:
case METHOD_LOG_IN:
loginBehaviorStr = call.argument(ARG_LOGIN_BEHAVIOR);
loginBehavior = loginBehaviorFromString(loginBehaviorStr, result);
List<String> readPermissions = call.argument(ARG_PERMISSIONS);
List<String> permissions = call.argument(ARG_PERMISSIONS);

delegate.logInWithReadPermissions(loginBehavior, readPermissions, result);
break;
case METHOD_LOG_IN_WITH_PUBLISH_PERMISSIONS:
loginBehaviorStr = call.argument(ARG_LOGIN_BEHAVIOR);
loginBehavior = loginBehaviorFromString(loginBehaviorStr, result);
List<String> publishPermissions = call.argument(ARG_PERMISSIONS);

delegate.logInWithPublishPermissions(loginBehavior, publishPermissions, result);
delegate.logIn(loginBehavior, permissions, result);
break;
case METHOD_LOG_OUT:
delegate.logOut(result);
Expand Down Expand Up @@ -113,20 +105,12 @@ public FacebookSignInDelegate(Registrar registrar) {
registrar.addActivityResultListener(resultDelegate);
}

public void logInWithReadPermissions(
LoginBehavior loginBehavior, List<String> permissions, Result result) {
resultDelegate.setPendingResult(METHOD_LOG_IN_WITH_READ_PERMISSIONS, result);

loginManager.setLoginBehavior(loginBehavior);
loginManager.logInWithReadPermissions(registrar.activity(), permissions);
}

public void logInWithPublishPermissions(
public void logIn(
LoginBehavior loginBehavior, List<String> permissions, Result result) {
resultDelegate.setPendingResult(METHOD_LOG_IN_WITH_PUBLISH_PERMISSIONS, result);
resultDelegate.setPendingResult(METHOD_LOG_IN, result);

loginManager.setLoginBehavior(loginBehavior);
loginManager.logInWithPublishPermissions(registrar.activity(), permissions);
loginManager.logIn(registrar.activity(), permissions);
}

public void logOut(Result result) {
Expand Down
1 change: 1 addition & 0 deletions example/ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
1 change: 1 addition & 0 deletions example/ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class _MyAppState extends State<MyApp> {

Future<Null> _login() async {
final FacebookLoginResult result =
await facebookSignIn.logInWithReadPermissions(['email']);
await facebookSignIn.logIn(['email']);

switch (result.status) {
case FacebookLoginStatus.loggedIn:
Expand Down
55 changes: 4 additions & 51 deletions ios/Classes/FacebookLoginPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,10 @@ - (BOOL)application:(UIApplication *)application

- (void)handleMethodCall:(FlutterMethodCall *)call
result:(FlutterResult)result {
if ([@"loginWithReadPermissions" isEqualToString:call.method]) {
FBSDKLoginBehavior behavior =
[self loginBehaviorFromString:call.arguments[@"behavior"]];
if ([@"logIn" isEqualToString:call.method]) {
NSArray *permissions = call.arguments[@"permissions"];

[self loginWithReadPermissions:behavior
permissions:permissions
result:result];
} else if ([@"loginWithPublishPermissions" isEqualToString:call.method]) {
FBSDKLoginBehavior behavior =
[self loginBehaviorFromString:call.arguments[@"behavior"]];
NSArray *permissions = call.arguments[@"permissions"];

[self loginWithPublishPermissions:behavior
permissions:permissions
result:result];
[self loginWithPermissions:permissions result:result];
} else if ([@"logOut" isEqualToString:call.method]) {
[self logOut:result];
} else if ([@"getCurrentAccessToken" isEqualToString:call.method]) {
Expand All @@ -79,30 +67,10 @@ - (void)handleMethodCall:(FlutterMethodCall *)call
}
}

- (FBSDKLoginBehavior)loginBehaviorFromString:(NSString *)loginBehaviorStr {
if ([@[ @"nativeWithFallback", @"nativeOnly" ]
containsObject:loginBehaviorStr]) {
return FBSDKLoginBehaviorNative;
} else if ([@"webOnly" isEqualToString:loginBehaviorStr]) {
return FBSDKLoginBehaviorBrowser;
} else if ([@"webViewOnly" isEqualToString:loginBehaviorStr]) {
return FBSDKLoginBehaviorWeb;
} else {
NSString *message = [NSString
stringWithFormat:@"Unknown login behavior: %@", loginBehaviorStr];

@throw [NSException exceptionWithName:@"InvalidLoginBehaviorException"
reason:message
userInfo:nil];
}
}

- (void)loginWithReadPermissions:(FBSDKLoginBehavior)behavior
permissions:(NSArray *)permissions
- (void)loginWithPermissions:(NSArray *)permissions
result:(FlutterResult)result {
[loginManager setLoginBehavior:behavior];
[loginManager
logInWithReadPermissions:permissions
logInWithPermissions:permissions
fromViewController:nil
handler:^(FBSDKLoginManagerLoginResult *loginResult,
NSError *error) {
Expand All @@ -112,21 +80,6 @@ - (void)loginWithReadPermissions:(FBSDKLoginBehavior)behavior
}];
}

- (void)loginWithPublishPermissions:(FBSDKLoginBehavior)behavior
permissions:(NSArray *)permissions
result:(FlutterResult)result {
[loginManager setLoginBehavior:behavior];
[loginManager
logInWithPublishPermissions:permissions
fromViewController:nil
handler:^(FBSDKLoginManagerLoginResult *loginResult,
NSError *error) {
[self handleLoginResult:loginResult
result:result
error:error];
}];
}

- (void)logOut:(FlutterResult)result {
[loginManager logOut];
result(nil);
Expand Down
7 changes: 3 additions & 4 deletions ios/flutter_facebook_login.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ A Flutter plugin for allowing users to authenticate with native Android &amp; iO
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'
s.dependency 'FBSDKCoreKit', '4.39.1'
s.dependency 'FBSDKLoginKit', '4.39.1'
s.dependency 'FBSDKCoreKit', '~> 5.5'
s.dependency 'FBSDKLoginKit', '~> 5.5'

# https://github.com/flutter/flutter/issues/14161
s.static_framework = true

s.ios.deployment_target = '8.0'
s.ios.deployment_target = '9.0'
end

44 changes: 6 additions & 38 deletions lib/flutter_facebook_login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'src/clock.dart';
/// ```dart
/// final facebookLogin = FacebookLogin();
/// final result =
/// await facebookLogin.logInWithReadPermissions(['email']);
/// await facebookLogin.logInWithPermissions(['email']);
///
/// switch (result.status) {
/// case FacebookLoginStatus.loggedIn:
Expand Down Expand Up @@ -99,38 +99,11 @@ class FacebookLogin {
/// Returns a [FacebookLoginResult] that contains relevant information about
/// the current login status. For sample code, see the [FacebookLogin] class-
/// level documentation.
Future<FacebookLoginResult> logInWithReadPermissions(
Future<FacebookLoginResult> logIn(
List<String> permissions,
) async {
final Map<dynamic, dynamic> result =
await channel.invokeMethod('loginWithReadPermissions', {
'behavior': _currentLoginBehaviorAsString(),
'permissions': permissions,
});

return _deliverResult(
FacebookLoginResult._(result.cast<String, dynamic>()));
}

/// Logs the user in with the requested publish permissions.
///
/// This will throw an exception from the native side if the [permissions]
/// list contains any permissions that are not classified as read permissions.
///
/// If called right after receiving a result from [logInWithReadPermissions],
/// this method may fail. It is recommended to call this method right before
/// needing a specific publish permission, in a context where it makes sense
/// to the user. For example, a good place to call this method would be when
/// the user is about to post something to Facebook by using your app.
///
/// Returns a [FacebookLoginResult] that contains relevant information about
/// the current login status. For sample code, see the [FacebookLogin] class-
/// level documentation.
Future<FacebookLoginResult> loginWithPublishPermissions(
List<String> permissions,
) async {
final Map<dynamic, dynamic> result =
await channel.invokeMethod('loginWithPublishPermissions', {
await channel.invokeMethod('logIn', {
'behavior': _currentLoginBehaviorAsString(),
'permissions': permissions,
});
Expand All @@ -143,17 +116,12 @@ class FacebookLogin {
///
/// NOTE: On iOS, this behaves in an unwanted way. As far the Login SDK is
/// concerned, the access token and session is cleared upon logging out.
/// However, when using [FacebookLoginBehavior.webOnly], the WKViewController
/// managed by Safari remembers the user indefinitely.
/// However, ViewController managed by Safari remembers the user indefinitely.
///
/// This blocks the user from logging in with any other account than the one
/// they used the first time. This same issue is also present when using
/// [FacebookLoginBehavior.nativeWithFallback] in the case where the user
/// doesn't have a native Facebook app installed.
///
/// Using [FacebookLoginBehavior.webViewOnly] resolves this issue.
/// they used the first time.
///
/// For more, see: https://github.com/roughike/flutter_facebook_login/issues/4
/// For more, see: https://github.com/facebook/facebook-swift-sdk/issues/215
Future<void> logOut() async => channel.invokeMethod('logOut');

String _currentLoginBehaviorAsString() {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_facebook_login
description: A Flutter plugin for allowing users to authenticate with native Android &amp; iOS Facebook login SDKs.
version: 2.0.1
version: 3.0.0
author: Iiro Krankka <iiro.krankka@gmail.com>
homepage: https://github.com/roughike/flutter_facebook_login

Expand Down
14 changes: 2 additions & 12 deletions test/custom_matchers.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
import 'package:flutter_test/flutter_test.dart';

Matcher isReadPermissionLoginWithBehavior(String behavior) {
Matcher isLoginWithBehavior(String behavior) {
return isMethodCall(
'loginWithReadPermissions',
'logIn',
arguments: {
'behavior': behavior,
'permissions': [],
},
);
}

Matcher isPublishPermissionLoginWithBehavior(String behavior) {
return isMethodCall(
'loginWithPublishPermissions',
arguments: {
'behavior': behavior,
'permissions': [],
},
);
}