|
|
@@ -2,7 +2,6 @@
|
|
|
// Swift-generated headers need these protocol definitions when compiled as Objective-C++.
|
|
|
#import <SafariServices/SafariServices.h>
|
|
|
#import <AuthenticationServices/AuthenticationServices.h>
|
|
|
-#import <AppTrackingTransparency/AppTrackingTransparency.h>
|
|
|
#import <FBSDKCoreKit/FBSDKCoreKit.h>
|
|
|
#import <FBSDKCoreKit/FBSDKCoreKit-Swift.h>
|
|
|
#import <FBSDKLoginKit/FBSDKLoginKit.h>
|
|
|
@@ -130,33 +129,12 @@
|
|
|
|
|
|
BOOL hasFacebookApp = [UIApplication.sharedApplication canOpenURL:[NSURL URLWithString:@"fbapi://"]] &&
|
|
|
[UIApplication.sharedApplication canOpenURL:[NSURL URLWithString:@"fbauth2://"]];
|
|
|
- BOOL trackingAllowed = [FBSDKSettings sharedSettings].isAdvertiserTrackingEnabled;
|
|
|
- if (@available(iOS 14.0, *)) {
|
|
|
- // Read only. Login must never prompt for ATT or be blocked by a denial.
|
|
|
- trackingAllowed = ATTrackingManager.trackingAuthorizationStatus == ATTrackingManagerAuthorizationStatusAuthorized;
|
|
|
- if (@available(iOS 17.0, *)) {
|
|
|
- // SDK reads ATT itself.
|
|
|
- } else {
|
|
|
- [FBSDKSettings sharedSettings].isAdvertiserTrackingEnabled = trackingAllowed;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Prefer the installed app. Without existing tracking consent, native login
|
|
|
- // can still use Limited Login when Meta enables Limited Login App Switch.
|
|
|
- // No installed app always uses Limited Login in the browser.
|
|
|
- FBSDKLoginTracking tracking = hasFacebookApp && trackingAllowed
|
|
|
- ? FBSDKLoginTrackingEnabled : FBSDKLoginTrackingLimited;
|
|
|
- NSString *nonce = NSUUID.UUID.UUIDString;
|
|
|
- FBSDKLoginConfiguration *config = [[FBSDKLoginConfiguration alloc]
|
|
|
- initWithPermissions:@[@"public_profile", @"email"] tracking:tracking nonce:nonce
|
|
|
- appSwitch:hasFacebookApp ? FBSDKAppSwitchEnabled : FBSDKAppSwitchDisabled];
|
|
|
- if (!config) {
|
|
|
- [self reply:request data:nil cancelled:NO error:@"Facebook 登录配置创建失败。"];
|
|
|
- return;
|
|
|
- }
|
|
|
+ NSArray<NSString *> *permissions = @[@"public_profile", @"email"];
|
|
|
+ // Match Unity FBUnityInterface: create a manager for this login and let the
|
|
|
+ // SDK handle the standard flow. Retain it through the asynchronous callback.
|
|
|
+ self.loginManager = [[FBSDKLoginManager alloc] init];
|
|
|
self.loginPending = YES;
|
|
|
- [self.loginManager logInFromViewController:self.presenter configuration:config
|
|
|
- completion:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
|
|
|
+ void (^loginHandler)(FBSDKLoginManagerLoginResult *, NSError *) = ^(FBSDKLoginManagerLoginResult *result, NSError *error) {
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
self.loginPending = NO;
|
|
|
if (error || result.isCancelled) {
|
|
|
@@ -165,16 +143,42 @@
|
|
|
}
|
|
|
NSString *accessToken = result.token.tokenString;
|
|
|
NSString *authenticationToken = result.authenticationToken.tokenString;
|
|
|
- if (tracking == FBSDKLoginTrackingEnabled && accessToken.length) {
|
|
|
+ if (accessToken.length) {
|
|
|
[self reply:request data:@{@"accessToken": accessToken, @"tokenType": @"access"} cancelled:NO error:nil];
|
|
|
} else if (authenticationToken.length) {
|
|
|
+ // The standard entry point generates its own nonce. Return the
|
|
|
+ // SDK token's nonce, never an unrelated locally generated value.
|
|
|
+ NSString *nonce = result.authenticationToken.nonce;
|
|
|
+ if (!nonce.length) {
|
|
|
+ [self reply:request data:nil cancelled:NO error:@"Facebook 身份令牌缺少 nonce。"];
|
|
|
+ return;
|
|
|
+ }
|
|
|
[self reply:request data:@{@"authenticationToken": authenticationToken,
|
|
|
@"tokenType": @"authentication", @"nonce": nonce} cancelled:NO error:nil];
|
|
|
} else {
|
|
|
[self reply:request data:nil cancelled:NO error:@"Facebook 登录未返回有效令牌。"];
|
|
|
}
|
|
|
});
|
|
|
- }];
|
|
|
+ };
|
|
|
+
|
|
|
+ if (hasFacebookApp) {
|
|
|
+ // Same entry point as Unity startLogin:scope:isPublishPermLogin:.
|
|
|
+ // nil asks the SDK to find its presenting view controller automatically.
|
|
|
+ [self.loginManager logInWithPermissions:permissions
|
|
|
+ fromViewController:nil
|
|
|
+ handler:loginHandler];
|
|
|
+ } else {
|
|
|
+ // Same configuration-based entry point as Unity loginWithTrackingPreference:.
|
|
|
+ FBSDKLoginConfiguration *config = [[FBSDKLoginConfiguration alloc]
|
|
|
+ initWithPermissions:permissions tracking:FBSDKLoginTrackingLimited
|
|
|
+ nonce:NSUUID.UUID.UUIDString appSwitch:FBSDKAppSwitchDisabled];
|
|
|
+ if (!config) {
|
|
|
+ self.loginPending = NO;
|
|
|
+ [self reply:request data:nil cancelled:NO error:@"Facebook 登录配置创建失败。"];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ [self.loginManager logInFromViewController:nil configuration:config completion:loginHandler];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- (void)share:(NSDictionary *)request params:(NSDictionary *)params {
|