mirror of
https://github.com/zhigang1992/facebook-ios-sdk.git
synced 2026-04-30 02:16:16 +08:00
Abstract Dependencies - FBSDKLoginManagerLogger
Summary: Abstracted `FBSDKAppEvents` from `FBSDKLoginManagerLogger` Reviewed By: samodom Differential Revision: D35660703 fbshipit-source-id: d2183038e74dbcd74aedca9db773bcb4857fa57e
This commit is contained in:
committed by
Facebook GitHub Bot
parent
5bf3953645
commit
e28f21d15b
@@ -32,7 +32,6 @@ file_name:
|
||||
ShareAppEventNames.swift,
|
||||
ShareAppEventParameters.swift,
|
||||
ShareDialogMode.swift,
|
||||
InternalUtilityExtensions.swift,
|
||||
LoginAppEventNames.swift,
|
||||
]
|
||||
trailing_comma:
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import FBSDKCoreKit
|
||||
|
||||
extension AppEvents: _LoginEventLogging {}
|
||||
@@ -54,11 +54,62 @@ static NSString *const FBSDKLoginManagerLoggerTryBrowser = @"trySafariAuth";
|
||||
@property (nonatomic) NSError *lastError;
|
||||
@property (nonatomic) NSString *authMethod;
|
||||
@property (nonatomic) NSString *loggingToken;
|
||||
@property (class, nonatomic) BOOL hasBeenConfigured;
|
||||
|
||||
@end
|
||||
|
||||
@implementation FBSDKLoginManagerLogger
|
||||
|
||||
// MARK: - Type Dependencies
|
||||
|
||||
static BOOL _hasBeenConfigured = false;
|
||||
static id<_FBSDKLoginEventLogging> _eventLogger;
|
||||
|
||||
+ (BOOL)hasBeenConfigured
|
||||
{
|
||||
return _hasBeenConfigured;
|
||||
}
|
||||
|
||||
+ (void)setHasBeenConfigured:(BOOL)hasBeenConfigured
|
||||
{
|
||||
_hasBeenConfigured = hasBeenConfigured;
|
||||
}
|
||||
|
||||
+ (id<_FBSDKLoginEventLogging>)eventLogger
|
||||
{
|
||||
return _eventLogger;
|
||||
}
|
||||
|
||||
+ (void)setEventLogger:(id<_FBSDKLoginEventLogging>)eventLogger
|
||||
{
|
||||
_eventLogger = eventLogger;
|
||||
}
|
||||
|
||||
+ (void)configureWithEventLogger:(id<_FBSDKLoginEventLogging>)eventLogger
|
||||
{
|
||||
self.eventLogger = eventLogger;
|
||||
self.hasBeenConfigured = true;
|
||||
}
|
||||
|
||||
+ (void)configureDefaultTypeDependencies
|
||||
{
|
||||
if (self.hasBeenConfigured) {
|
||||
return;
|
||||
}
|
||||
|
||||
[self configureWithEventLogger:FBSDKAppEvents.shared];
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
|
||||
+ (void)resetTypeDependencies
|
||||
{
|
||||
self.eventLogger = nil;
|
||||
self.hasBeenConfigured = false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+ (nullable FBSDKLoginManagerLogger *)loggerFromParameters:(nullable NSDictionary<NSString *, id> *)parameters
|
||||
tracking:(FBSDKLoginTracking)tracking
|
||||
{
|
||||
@@ -80,6 +131,8 @@ static NSString *const FBSDKLoginManagerLoggerTryBrowser = @"trySafariAuth";
|
||||
- (nullable instancetype)initWithLoggingToken:(NSString *)loggingToken
|
||||
tracking:(FBSDKLoginTracking)tracking
|
||||
{
|
||||
[self.class configureDefaultTypeDependencies];
|
||||
|
||||
switch (tracking) {
|
||||
case FBSDKLoginTrackingEnabled:
|
||||
break;
|
||||
@@ -117,8 +170,8 @@ static NSString *const FBSDKLoginManagerLoggerTryBrowser = @"trySafariAuth";
|
||||
- (void)endSession
|
||||
{
|
||||
[self logEvent:FBSDKAppEventNameFBSessionAuthEnd result:_lastResult error:_lastError];
|
||||
if (FBSDKAppEvents.shared.flushBehavior != FBSDKAppEventsFlushBehaviorExplicitOnly) {
|
||||
[FBSDKAppEvents.shared flush];
|
||||
if (self.class.eventLogger.flushBehavior != FBSDKAppEventsFlushBehaviorExplicitOnly) {
|
||||
[self.class.eventLogger flush];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,9 +314,9 @@ static NSString *const FBSDKLoginManagerLoggerTryBrowser = @"trySafariAuth";
|
||||
}
|
||||
[_extras removeAllObjects];
|
||||
|
||||
[FBSDKAppEvents.shared logInternalEvent:eventName
|
||||
parameters:params
|
||||
isImplicitlyLogged:YES];
|
||||
[self.class.eventLogger logInternalEvent:eventName
|
||||
parameters:params
|
||||
isImplicitlyLogged:YES];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import FBSDKCoreKit
|
||||
|
||||
/**
|
||||
Internal Type exposed to facilitate transition to Swift.
|
||||
API Subject to change or removal without warning. Do not use.
|
||||
|
||||
@warning INTERNAL - DO NOT USE
|
||||
*/
|
||||
@objc(_FBSDKLoginEventLogging)
|
||||
public protocol _LoginEventLogging {
|
||||
var flushBehavior: AppEvents.FlushBehavior { get }
|
||||
|
||||
func logInternalEvent(
|
||||
_ eventName: AppEvents.Name,
|
||||
parameters: [AppEvents.ParameterName: Any]?,
|
||||
isImplicitlyLogged: Bool
|
||||
)
|
||||
|
||||
func flush()
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import "FBSDKLoginManagerLogger.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface FBSDKLoginManagerLogger (Testing)
|
||||
|
||||
@property (class, nonatomic) id<_FBSDKLoginEventLogging> eventLogger;
|
||||
|
||||
+ (void)configureWithEventLogger:(id<_FBSDKLoginEventLogging>)eventLogger;
|
||||
|
||||
#if DEBUG
|
||||
+ (void)resetTypeDependencies;
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
Reference in New Issue
Block a user