Skip to content

Commit

Permalink
Facebook iOS SDK 4.17
Browse files Browse the repository at this point in the history
  • Loading branch information
David Emmel committed Oct 26, 2016
2 parents a8b14df + 514a8c8 commit d001870
Show file tree
Hide file tree
Showing 50 changed files with 1,620 additions and 117 deletions.
1 change: 1 addition & 0 deletions .buckversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3a688647b6fca77bda05ab55f2f53860a470edfc
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ Carthage

# vim temp files
*.swp

# buck
buck-out/
.buckd/
4 changes: 1 addition & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
[submodule "vendor/xctool"]
path = vendor/xctool
url = https://github.com/facebook/xctool.git


[submodule "FBNotifications"]
path = FBNotifications
url = https://github.com/facebook/FBNotifications.git
[submodule "vendor/FBTweak"]
path = vendor/FBTweak
url = git://github.com/facebook/Tweaks.git
url = https://github.com/facebook/Tweaks.git
2 changes: 1 addition & 1 deletion Configurations/Version.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

// The versions for FBSDK and Messenger SDK.
FBSDK_PROJECT_VERSION=4.16.1
FBSDK_PROJECT_VERSION=4.17.0
MNSDK_PROJECT_VERSION=TODO_SUPPORT_MNSDK

4 changes: 2 additions & 2 deletions FBSDKCoreKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Pod::Spec.new do |s|

s.name = "FBSDKCoreKit"
s.version = "4.16.1"
s.version = "4.17.0"
s.summary = "Official Facebook SDK for iOS to access Facebook Platform's core features"

s.description = <<-DESC
Expand All @@ -22,7 +22,7 @@ Pod::Spec.new do |s|
s.tvos.deployment_target = '9.0'

s.source = { :git => "https://github.com/facebook/facebook-ios-sdk.git",
:tag => "sdk-version-4.16.1"
:tag => "sdk-version-4.17.0"
}

s.ios.weak_frameworks = 'Accounts', 'CoreLocation', 'Social', 'Security', 'QuartzCore', 'CoreGraphics', 'UIKit', 'Foundation', 'AudioToolbox'
Expand Down
54 changes: 53 additions & 1 deletion FBSDKCoreKit/FBSDKCoreKit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions FBSDKCoreKit/FBSDKCoreKit/FBSDKAppEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#import <Foundation/Foundation.h>

#import <FBSDKCoreKit/FBSDKGraphRequestConnection.h>

#import "FBSDKMacros.h"

@class FBSDKAccessToken;
Expand Down Expand Up @@ -496,4 +498,24 @@ FBSDK_EXTERN NSString *const FBSDKAppEventParameterValueNo;
via the `[FBSDKSettings limitEventAndDataUsage]` flag, or a specific Facebook user cannot be identified.
*/
+ (FBSDKGraphRequest *)requestForCustomAudienceThirdPartyIDWithAccessToken:(FBSDKAccessToken *)accessToken;

/*
@abstract Sets a custom user ID to associate with all app events.
@discussion The userID is persisted until it is cleared by passing nil.
*/
+ (void)setUserID:(NSString *)userID;

/*
@abstract Returns the set custom user ID.
*/
+ (NSString *)userID;

/*
@abstract Sends a request to update the properties for the current user, set by `setUserID:`
@discussion You must call `FBSDKAppEvents setUserID:` before making this call.
@param properties the custom user properties
@param handler the optional completion handler
*/
+ (void)updateUserProperties:(NSDictionary *)properties handler:(FBSDKGraphRequestHandler)handler;

@end
72 changes: 72 additions & 0 deletions FBSDKCoreKit/FBSDKCoreKit/FBSDKAppEvents.m
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@
NSString *const FBSDKAppEventNameFBSDKSendButtonImpression = @"fb_send_button_impression";
NSString *const FBSDKAppEventNameFBSDKShareButtonImpression = @"fb_share_button_impression";

NSString *const FBSDKAppEventNameFBSDKSmartLoginService = @"fb_smart_login_service";

NSString *const FBSDKAppEventNameFBSDKLikeButtonDidTap = @"fb_like_button_did_tap";
NSString *const FBSDKAppEventNameFBSDKLoginButtonDidTap = @"fb_login_button_did_tap";
NSString *const FBSDKAppEventNameFBSDKSendButtonDidTap = @"fb_send_button_did_tap";
Expand All @@ -142,6 +144,8 @@
NSString *const FBSDKAppEventNameFBSDKEventMessengerShareDialogShow = @"fb_messenger_dialog_share_show";
NSString *const FBSDKAppEventNameFBSDKEventAppInviteShareDialogShow = @"fb_app_invite_share_show";

NSString *const FBSDKAppEventNameFBSessionNativeAppSwitchLoginDialogResult = @"fb_mobile_login_native_app_switch_dialog_result";

// Event Parameters internal to this file
NSString *const FBSDKAppEventParameterDialogOutcome = @"fb_dialog_outcome";
NSString *const FBSDKAppEventParameterDialogErrorMessage = @"fb_dialog_outcome_error_message";
Expand Down Expand Up @@ -191,6 +195,7 @@
#define NUM_LOG_EVENTS_TO_TRY_TO_FLUSH_AFTER 100
#define FLUSH_PERIOD_IN_SECONDS 15
#define APP_SUPPORTS_ATTRIBUTION_ID_RECHECK_PERIOD 60 * 60 * 24
#define USER_ID_USER_DEFAULTS_KEY @"com.facebook.sdk.appevents.userid"

static NSString *g_overrideAppID = nil;

Expand All @@ -211,6 +216,7 @@ @implementation FBSDKAppEvents
NSTimer *_attributionIDRecheckTimer;
FBSDKServerConfiguration *_serverConfiguration;
FBSDKAppEventsState *_appEventsState;
NSString *_userID;
}

#pragma mark - Object Lifecycle
Expand Down Expand Up @@ -256,6 +262,9 @@ - (FBSDKAppEvents *)init
selector:@selector(applicationDidBecomeActive)
name:UIApplicationDidBecomeActiveNotification
object:NULL];

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
_userID = [defaults stringForKey:USER_ID_USER_DEFAULTS_KEY];
}

return self;
Expand Down Expand Up @@ -443,6 +452,68 @@ + (void)flush
[[FBSDKAppEvents singleton] flushForReason:FBSDKAppEventsFlushReasonExplicit];
}

+ (void)setUserID:(NSString *)userID
{
if ([[[self class] singleton]->_userID isEqualToString:userID]) {
return;
}
[[self class] singleton]->_userID = userID;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:userID forKey:USER_ID_USER_DEFAULTS_KEY];
[defaults synchronize];
}

+ (NSString *)userID
{
return [[self class] singleton]->_userID;
}

+ (void)updateUserProperties:(NSDictionary *)properties handler:(FBSDKGraphRequestHandler)handler
{
NSString *userID = [[self class] userID];

if (userID.length == 0) {
[FBSDKLogger singleShotLogEntry:FBSDKLoggingBehaviorDeveloperErrors logEntry:@"Missing [FBSDKAppEvents userID] for [FBSDKAppEvents updateUserProperties:]"];
NSError *error = [FBSDKError requiredArgumentErrorWithName:@"userID" message:@"Missing [FBSDKAppEvents userID] for [FBSDKAppEvents updateUserProperties:]"];
if (handler) {
handler(nil, nil, error);
}
return;
}
NSMutableDictionary *dataDictionary = [NSMutableDictionary dictionaryWithCapacity:3];
dataDictionary[@"user_unique_id"] = [FBSDKAppEvents userID];
[FBSDKInternalUtility dictionary:dataDictionary setObject:[FBSDKAppEventsUtility advertiserID] forKey:@"advertiser_id"];
[FBSDKInternalUtility dictionary:dataDictionary setObject:properties forKey:@"custom_data"];

NSError *error;
__block NSError *invalidObjectError;
NSString *dataJSONString = [FBSDKInternalUtility JSONStringForObject:@[dataDictionary] error:&error invalidObjectHandler:^id(id object, BOOL *stop) {
*stop = YES;
invalidObjectError = [FBSDKError unknownErrorWithMessage:@"The values in the properties dictionary must be NSStrings or NSNumbers"];
return nil;
}];
if (!error) {
error = invalidObjectError;
}
if (error) {
[FBSDKLogger singleShotLogEntry:FBSDKLoggingBehaviorDeveloperErrors logEntry:@"Failed to serialize properties for [FBSDKAppEvents updateUserProperties:]"];
if (handler) {
handler(nil, nil, error);
}
return;
}
NSDictionary *params = @{ @"data" : dataJSONString };
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:[NSString stringWithFormat:@"%@/user_properties", [FBSDKSettings appID]]
parameters:params
tokenString:[FBSDKAccessToken currentAccessToken].tokenString
HTTPMethod:@"POST"
flags:FBSDKGraphRequestFlagDisableErrorRecovery |
FBSDKGraphRequestFlagDoNotInvalidateTokenOnError |
FBSDKGraphRequestFlagSkipClientToken
];
[request startWithCompletionHandler:handler];
}

#pragma mark - Internal Methods

+ (void)logImplicitEvent:(NSString *)eventName
Expand Down Expand Up @@ -593,6 +664,7 @@ - (void)instanceLogEvent:(NSString *)eventName
if (isImplicitlyLogged) {
eventDictionary[FBSDKAppEventParameterImplicitlyLogged] = @"1";
}
[FBSDKInternalUtility dictionary:eventDictionary setObject:_userID forKey:@"_app_user_id"];

NSString *currentViewControllerName;
if ([NSThread isMainThread]) {
Expand Down
2 changes: 2 additions & 0 deletions FBSDKCoreKit/FBSDKCoreKit/FBSDKApplicationDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation;

#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_9_3
/*!
@abstract
Call this method from the [UIApplicationDelegate application:openURL:options:] method
Expand All @@ -75,6 +76,7 @@
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options;
#endif

/*!
@abstract
Expand Down
74 changes: 49 additions & 25 deletions FBSDKCoreKit/FBSDKCoreKit/FBSDKApplicationDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
#import "FBSDKProfile+Internal.h"
#endif

// TODO: t13635729 Remove when Sandcastle builds witn Xcode8
@interface UIApplication (iOS10)

- (void)openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options completionHandler:(void (^)(BOOL))completion;

@end

NSString *const FBSDKApplicationDidBecomeActiveNotification = @"com.facebook.sdk.FBSDKApplicationDidBecomeActiveNotification";

static NSString *const FBSDKAppLinkInboundEvent = @"fb_al_inbound";
Expand All @@ -54,6 +61,7 @@ @implementation FBSDKApplicationDelegate
#endif
BOOL _expectingBackground;
UIViewController *_safariViewController;
BOOL _isDismissingSafariViewController;
}

#pragma mark - Class Methods
Expand Down Expand Up @@ -122,6 +130,7 @@ - (void)dealloc

#pragma mark - UIApplicationDelegate

#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_9_3
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
Expand All @@ -131,6 +140,7 @@ - (BOOL)application:(UIApplication *)application
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
}
#endif

- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
Expand All @@ -145,21 +155,30 @@ - (BOOL)application:(UIApplication *)application
[FBSDKTimeSpentData setSourceApplication:sourceApplication openURL:url];

#if !TARGET_OS_TV
// if they completed a SFVC flow, dismiss it.
[_safariViewController.presentingViewController dismissViewControllerAnimated:YES completion: nil];
_safariViewController = nil;

if (_pendingURLOpen) {
id<FBSDKURLOpening> pendingURLOpen = _pendingURLOpen;
id<FBSDKURLOpening> pendingURLOpen = _pendingURLOpen;

void (^completePendingOpenURLBlock)(void) = ^{
_pendingURLOpen = nil;

if ([pendingURLOpen application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation]) {
return YES;
}
[pendingURLOpen application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
_isDismissingSafariViewController = NO;
};
// if they completed a SFVC flow, dismiss it.
if (_safariViewController) {
_isDismissingSafariViewController = YES;
[_safariViewController.presentingViewController dismissViewControllerAnimated:YES
completion:completePendingOpenURLBlock];
_safariViewController = nil;
} else {
completePendingOpenURLBlock();
}
if ([pendingURLOpen canOpenURL:url
forApplication:application
sourceApplication:sourceApplication
annotation:annotation]) {
return YES;
}
if ([self _handleBridgeAPIResponseURL:url sourceApplication:sourceApplication]) {
return YES;
Expand Down Expand Up @@ -209,7 +228,7 @@ - (void)applicationDidBecomeActive:(NSNotification *)notification
// _expectingBackground can be YES if the caller started doing work (like login)
// within the app delegate's lifecycle like openURL, in which case there
// might have been a "didBecomeActive" event pending that we want to ignore.
if (!_expectingBackground && !_safariViewController) {
if (!_expectingBackground && !_safariViewController && !_isDismissingSafariViewController) {
_active = YES;
#if !TARGET_OS_TV
[_pendingURLOpen applicationDidBecomeActive:[notification object]];
Expand All @@ -231,18 +250,23 @@ - (void)openURL:(NSURL *)url sender:(id<FBSDKURLOpening>)sender handler:(void(^)
_pendingURLOpen = sender;
dispatch_async(dispatch_get_main_queue(), ^{
// Dispatch openURL calls to prevent hangs if we're inside the current app delegate's openURL flow already
BOOL opened = [[UIApplication sharedApplication] openURL:url];

if ([url.scheme hasPrefix:@"http"] && !opened) {
NSOperatingSystemVersion iOS8Version = { .majorVersion = 8, .minorVersion = 0, .patchVersion = 0 };
if (![FBSDKInternalUtility isOSRunTimeVersionAtLeast:iOS8Version]) {
// Safari openURL calls can wrongly return NO on iOS 7 so manually overwrite that case to YES.
// Otherwise we would rather trust in the actual result of openURL
opened = YES;
NSOperatingSystemVersion iOS10Version = { .majorVersion = 10, .minorVersion = 0, .patchVersion = 0 };
if ([FBSDKInternalUtility isOSRunTimeVersionAtLeast:iOS10Version]) {
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:handler];
} else {
BOOL opened = [[UIApplication sharedApplication] openURL:url];

if ([url.scheme hasPrefix:@"http"] && !opened) {
NSOperatingSystemVersion iOS8Version = { .majorVersion = 8, .minorVersion = 0, .patchVersion = 0 };
if (![FBSDKInternalUtility isOSRunTimeVersionAtLeast:iOS8Version]) {
// Safari openURL calls can wrongly return NO on iOS 7 so manually overwrite that case to YES.
// Otherwise we would rather trust in the actual result of openURL
opened = YES;
}
}
if (handler) {
handler(opened);
}
}
if (handler) {
handler(opened);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@
#import <FBSDKCoreKit/FBSDKDeviceViewControllerBase.h>
#endif

#define FBSDK_VERSION_STRING @"4.16.1"
#define FBSDK_VERSION_STRING @"4.17.0"
#define FBSDK_TARGET_PLATFORM_VERSION @"v2.8"
8 changes: 6 additions & 2 deletions FBSDKCoreKit/FBSDKCoreKit/FBSDKDeviceViewControllerBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ - (instancetype)init

- (void)loadView
{
FBSDKDeviceDialogView *deviceView = [[FBSDKDeviceDialogView alloc] initWithFrame:[UIScreen mainScreen].bounds];
CGRect frame = [UIScreen mainScreen].bounds;
BOOL smartLoginEnabled = ([FBSDKServerConfigurationManager cachedServerConfiguration].smartLoginOptions & FBSDKServerConfigurationSmartLoginOptionsEnabled);
FBSDKDeviceDialogView *deviceView =
(smartLoginEnabled ?
[[FBSDKSmartDeviceDialogView alloc] initWithFrame:frame] :
[[FBSDKDeviceDialogView alloc] initWithFrame:frame] );
deviceView.delegate = self;
self.view = deviceView;
}
Expand Down Expand Up @@ -118,5 +123,4 @@ - (void)deviceDialogViewDidCancel:(FBSDKDeviceDialogView *)deviceDialogView
{
[self dismissViewControllerAnimated:YES completion:NULL];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ FBSDK_EXTERN NSString *const FBSDKAppEventNameFBDialogsNativeLoginDialogEnd;
/*! Use to log the e2e timestamp metrics for web login */
FBSDK_EXTERN NSString *const FBSDKAppEventNameFBDialogsWebLoginCompleted;

/*! Use to log the result of the App Switch OS AlertView. Only available on OS >= iOS10 */
FBSDK_EXTERN NSString *const FBSDKAppEventNameFBSessionNativeAppSwitchLoginDialogResult;

/*! Use to log the results of a share dialog */
FBSDK_EXTERN NSString *const FBSDLAppEventNameFBSDKEventShareDialogResult;
FBSDK_EXTERN NSString *const FBSDKAppEventNameFBSDKEventMessengerShareDialogResult;
Expand Down Expand Up @@ -129,6 +132,8 @@ FBSDK_EXTERN NSString *const FBSDKAppEventNameFBSDKLoginButtonImpression;
FBSDK_EXTERN NSString *const FBSDKAppEventNameFBSDKSendButtonImpression;
FBSDK_EXTERN NSString *const FBSDKAppEventNameFBSDKShareButtonImpression;

FBSDK_EXTERN NSString *const FBSDKAppEventNameFBSDKSmartLoginService;

FBSDK_EXTERN NSString *const FBSDKAppEventNameFBSDKLikeButtonDidTap;
FBSDK_EXTERN NSString *const FBSDKAppEventNameFBSDKLoginButtonDidTap;
FBSDK_EXTERN NSString *const FBSDKAppEventNameFBSDKSendButtonDidTap;
Expand Down
Loading

0 comments on commit d001870

Please sign in to comment.