Skip to content

Commit

Permalink
Facebook iOS SDK 4.11
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisp-fb committed Apr 12, 2016
2 parents e96f044 + 6d5b82a commit 4f4cdf4
Show file tree
Hide file tree
Showing 112 changed files with 3,827 additions and 822 deletions.
2 changes: 1 addition & 1 deletion Bolts-IOS
Submodule Bolts-IOS updated from beac94 to d293c4
14 changes: 6 additions & 8 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.10.1"
s.version = "4.11.0"
s.summary = "Official Facebook SDK for iOS to access Facebook Platform's core features"

s.description = <<-DESC
Expand All @@ -22,19 +22,17 @@ 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.10.1"
:tag => "sdk-version-4.11.0"
}

s.ios.weak_frameworks = 'Accounts', 'CoreLocation', 'Social', 'Security', 'QuartzCore', 'CoreGraphics', 'UIKit', 'Foundation', 'AudioToolbox'
s.tvos.weak_frameworks = 'CoreLocation', 'Security', 'QuartzCore', 'CoreGraphics', 'UIKit', 'Foundation', 'AudioToolbox'

s.header_dir = "FBSDKCoreKit"

# set header_mappings_dir to resolve our quoted imports in the +Internal file.
s.header_mappings_dir = "FBSDKCoreKit/FBSDKCoreKit"

s.public_header_files = 'FBSDKCoreKit/FBSDKCoreKit/*.h'
s.source_files = 'FBSDKCoreKit/FBSDKCoreKit/**/*.{h,m}'
s.ios.exclude_files = 'FBSDKCoreKit/FBSDKCoreKit/FBSDKDeviceButton.{h,m}',
'FBSDKCoreKit/FBSDKCoreKit/FBSDKDeviceViewControllerBase.{h,m}',
'FBSDKCoreKit/FBSDKCoreKit/Internal/Device/**/*'
s.tvos.exclude_files = 'FBSDKCoreKit/FBSDKCoreKit/FBSDKAppLinkResolver.{h,m}',
'FBSDKCoreKit/FBSDKCoreKit/FBSDKAppLinkUtility.{h,m}',
'FBSDKCoreKit/FBSDKCoreKit/FBSDKGraphErrorRecoveryProcessor.{h,m}',
Expand All @@ -59,5 +57,5 @@ Pod::Spec.new do |s|
s.requires_arc = ['FBSDKCoreKit/FBSDKCoreKit/*',
'FBSDKCoreKit/FBSDKCoreKit/Internal/**/*']

s.ios.dependency 'Bolts', '~> 1.5'
s.ios.dependency 'Bolts', '~> 1.7'
end
105 changes: 105 additions & 0 deletions FBSDKCoreKit/FBSDKCoreKit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions FBSDKCoreKit/FBSDKCoreKit/FBSDKAppEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,28 @@ FBSDK_EXTERN NSString *const FBSDKAppEventParameterValueNo;
parameters:(NSDictionary *)parameters
accessToken:(FBSDKAccessToken *)accessToken;


/*
* Push Notifications Logging
*/

/*!
@abstract
Log an app event that tracks that the application was open via Push Notification.
@param payload Notification payload received via `UIApplicationDelegate`.
*/
+ (void)logPushNotificationOpen:(NSDictionary *)payload;

/*!
@abstract
Log an app event that tracks that a custom action was taken from a push notification.
@param payload Notification payload received via `UIApplicationDelegate`.
@param action Name of the action that was taken.
*/
+ (void)logPushNotificationOpen:(NSDictionary *)payload action:(NSString *)action;

/*!
@abstract
Expand All @@ -381,6 +403,21 @@ FBSDK_EXTERN NSString *const FBSDKAppEventParameterValueNo;
*/
+ (void)activateApp;

/*
* Push Notifications Registration
*/

/*!
@abstract
Sets a device token to register the current application installation for push notifications.
@discussion
Sets a device token from `NSData` representation that you get from `UIApplicationDelegate.-application:didRegisterForRemoteNotificationsWithDeviceToken:`.
@param deviceToken Device token data.
*/
+ (void)setPushNotificationsDeviceToken:(NSData *)deviceToken;

/*
* Control over event batching/flushing
*/
Expand Down
64 changes: 61 additions & 3 deletions FBSDKCoreKit/FBSDKCoreKit/FBSDKAppEvents.m
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@
NSString *const FBSDKAppEventParameterDialogErrorMessage = @"fb_dialog_outcome_error_message";
NSString *const FBSDKAppEventParameterDialogMode = @"fb_dialog_mode";
NSString *const FBSDKAppEventParameterDialogShareContentType = @"fb_dialog_share_content_type";
NSString *const FBSDKAppEventParameterLogTime = @"_logTime";
NSString *const FBSDKAppEventParameterEventName = @"_eventName";
NSString *const FBSDKAppEventParameterImplicitlyLogged = @"_implicitlyLogged";

// Event parameter values internal to this file
NSString *const FBSDKAppEventsDialogOutcomeValue_Completed = @"Completed";
Expand All @@ -172,6 +175,19 @@

NSString *const FBSDKAppEventsOverrideAppIDBundleKey = @"FacebookLoggingOverrideAppID";

//
// Push Notifications
// Activities Endpoint Parameter
static NSString *const FBSDKActivitesParameterPushDeviceToken = @"device_token";
// Event Name
static NSString *const FBSDKAppEventNamePushOpened = @"fb_mobile_push_opened";
// Event Parameter
static NSString *const FBSDKAppEventParameterPushCampaign = @"fb_push_campaign";
static NSString *const FBSDKAppEventParameterPushAction = @"fb_push_action";
// Payload Keys
static NSString *const FBSDKAppEventsPushPayloadKey = @"fb_push_payload";
static NSString *const FBSDKAppEventsPushPayloadCampaignKey = @"campaign";

#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
Expand All @@ -183,6 +199,9 @@ @interface FBSDKAppEvents ()
@property (nonatomic, readwrite) FBSDKAppEventsFlushBehavior flushBehavior;
//for testing only.
@property (nonatomic, assign) BOOL disableTimer;

@property (nonatomic, copy) NSString *pushNotificationsDeviceTokenString;

@end

@implementation FBSDKAppEvents
Expand Down Expand Up @@ -344,6 +363,35 @@ + (void)logPurchase:(double)purchaseAmount
}
}

/*
* Push Notifications Logging
*/

+ (void)logPushNotificationOpen:(NSDictionary *)payload
{
[self logPushNotificationOpen:payload action:nil];
}

+ (void)logPushNotificationOpen:(NSDictionary *)payload action:(NSString *)action
{
NSDictionary *facebookPayload = payload[FBSDKAppEventsPushPayloadKey];
if (!facebookPayload) {
return;
}
NSString *campaign = facebookPayload[FBSDKAppEventsPushPayloadCampaignKey];
if (campaign.length == 0) {
[FBSDKLogger singleShotLogEntry:FBSDKLoggingBehaviorDeveloperErrors
logEntry:@"Malformed payload specified for logging a push notification open."];
return;
}

NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithObject:campaign forKey:FBSDKAppEventParameterPushCampaign];
if (action) {
parameters[FBSDKAppEventParameterPushAction] = action;
}
[self logEvent:FBSDKAppEventNamePushOpened parameters:parameters];
}

+ (void)activateApp
{
[FBSDKAppEventsUtility ensureOnMainThread:NSStringFromSelector(_cmd) className:NSStringFromClass(self)];
Expand All @@ -360,6 +408,11 @@ + (void)activateApp
[FBSDKTimeSpentData restore:YES];
}

+ (void)setPushNotificationsDeviceToken:(NSData *)deviceToken
{
[FBSDKAppEvents singleton].pushNotificationsDeviceTokenString = [FBSDKInternalUtility hexadecimalStringFromData:deviceToken];
}

+ (FBSDKAppEventsFlushBehavior)flushBehavior
{
return [FBSDKAppEvents singleton].flushBehavior;
Expand Down Expand Up @@ -532,11 +585,13 @@ - (void)instanceLogEvent:(NSString *)eventName
}

NSMutableDictionary *eventDictionary = [NSMutableDictionary dictionaryWithDictionary:parameters];
eventDictionary[@"_eventName"] = eventName;
eventDictionary[@"_logTime"] = @([FBSDKAppEventsUtility unixTimeNow]);
eventDictionary[FBSDKAppEventParameterEventName] = eventName;
if (!eventDictionary[FBSDKAppEventParameterLogTime]) {
eventDictionary[FBSDKAppEventParameterLogTime] = @([FBSDKAppEventsUtility unixTimeNow]);
}
[FBSDKInternalUtility dictionary:eventDictionary setObject:valueToSum forKey:@"_valueToSum"];
if (isImplicitlyLogged) {
eventDictionary[@"_implicitlyLogged"] = @"1";
eventDictionary[FBSDKAppEventParameterImplicitlyLogged] = @"1";
}

NSString *currentViewControllerName;
Expand Down Expand Up @@ -650,6 +705,9 @@ - (void)flushOnMainQueue:(FBSDKAppEventsState *)appEventsState
if (appEventsState.numSkipped > 0) {
postParameters[@"num_skipped_events"] = [NSString stringWithFormat:@"%lu", (unsigned long)appEventsState.numSkipped];
}
if (self.pushNotificationsDeviceTokenString) {
postParameters[FBSDKActivitesParameterPushDeviceToken] = self.pushNotificationsDeviceTokenString;
}

NSString *loggingEntry = nil;
if ([[FBSDKSettings loggingBehavior] containsObject:FBSDKLoggingBehaviorAppEvents]) {
Expand Down
21 changes: 6 additions & 15 deletions FBSDKCoreKit/FBSDKCoreKit/FBSDKAppLinkResolver.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#import "FBSDKGraphRequest+Internal.h"
#import "FBSDKGraphRequestConnection.h"
#import "FBSDKInternalUtility.h"
#import "FBSDKLogger.h"
#import "FBSDKSettings+Internal.h"
#import "FBSDKUtility.h"
Expand All @@ -41,17 +42,6 @@
static NSString *const kShouldFallbackKey = @"should_fallback";
static NSString *const kAppLinksKey = @"app_links";

static void FBSDKAppLinkResolverBoltsClassFromString(Class *clazz, NSString *className)
{
*clazz = NSClassFromString(className);
if (*clazz == nil) {
NSString *message = [NSString stringWithFormat:@"Unable to load class %@. Did you link Bolts.framework?", className];
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:message
userInfo:nil];
}
}

@interface FBSDKAppLinkResolver ()

@property (nonatomic, strong) NSMutableDictionary *cachedLinks;
Expand All @@ -68,10 +58,11 @@ @implementation FBSDKAppLinkResolver
+ (void)initialize
{
if (self == [FBSDKAppLinkResolver class]) {
FBSDKAppLinkResolverBoltsClassFromString(&g_BFTaskCompletionSourceClass, @"BFTaskCompletionSource");
FBSDKAppLinkResolverBoltsClassFromString(&g_BFAppLinkTargetClass, @"BFAppLinkTarget");
FBSDKAppLinkResolverBoltsClassFromString(&g_BFAppLinkClass, @"BFAppLink");
FBSDKAppLinkResolverBoltsClassFromString(&g_BFTaskClass, @"BFTask");
g_BFTaskCompletionSourceClass = [FBSDKInternalUtility
resolveBoltsClassWithName:@"BFTaskCompletionSource"];
g_BFAppLinkTargetClass = [FBSDKInternalUtility resolveBoltsClassWithName:@"BFAppLinkTarget"];
g_BFTaskClass = [FBSDKInternalUtility resolveBoltsClassWithName:@"BFTask"];
g_BFAppLinkClass = [FBSDKInternalUtility resolveBoltsClassWithName:@"BFAppLink"];
}
}

Expand Down
45 changes: 45 additions & 0 deletions FBSDKCoreKit/FBSDKCoreKit/FBSDKAppLinkUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
*/
typedef void (^FBSDKDeferredAppLinkHandler)(NSURL *url, NSError *error);


/*!
@abstract Describes the callback for fetchOrganicDeferredAppLink.
@param url the url representing the deferred App Link
*/
typedef void (^FBSDKDeferredAppInviteHandler)(NSURL *url);


/*!
@abstract Class containing App Links related utility methods.
*/
Expand All @@ -52,4 +60,41 @@ typedef void (^FBSDKDeferredAppLinkHandler)(NSURL *url, NSError *error);
*/
+ (void)fetchDeferredAppLink:(FBSDKDeferredAppLinkHandler)handler;

/*!
@abstract Call this method from the main thread to fetch deferred deeplink for App Invites
Handler is called with deeplink url, if found, nil otherwise.
@param handler Handler to be called when we fetch deeplink url.
@return YES if async fetch process was started, NO if it failed to start. Note it returns NO
for versions < iOS 9.
@discussion Call this method from the main thread to fetch deferred deeplink if you use App Invites.
This may require a network round trip. If successful, this will call the handler provided, with
deferred deeplink that was clicked by the user. If there is a error/timeout, handler will be called
with nil.
This method only works on iOS 9+ and returns NO otherwise.
This method should only be called from a location that occurs after any launching URL has
been processed (e.g., you should call this method from your application delegate's
didFinishLaunchingWithOptions:).
*/
+ (BOOL)fetchDeferredAppInvite:(FBSDKDeferredAppInviteHandler)handler;

/*
@abstract Call this method to fetch promotion code from the url, if it's present. This function
requires Bolts framework.
Note: This throws an exception if Bolts.framework is not linked. Add '[BFURL class]' in intialize method
of your AppDelegate.
@param url App Link url that was passed to the app.
@return Promotion code string.
@discussion Call this method to fetch App Invite Promotion Code from applink if present.
This can be used to fetch the promotion code that was associated with the invite when it
was created. This method should be called with the url from the openURL method.
*/
+ (NSString*)appInvitePromotionCodeFromURL:(NSURL*)url;

@end
34 changes: 34 additions & 0 deletions FBSDKCoreKit/FBSDKCoreKit/FBSDKAppLinkUtility.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@

#import "FBSDKAppLinkUtility.h"

#import <Bolts/BFURL.h>

#import "FBSDKAppEventsUtility.h"
#import "FBSDKGraphRequest.h"
#import "FBSDKInternalUtility.h"
#import "FBSDKOrganicDeeplinkHelper.h"
#import "FBSDKSettings.h"
#import "FBSDKUtility.h"

Expand Down Expand Up @@ -77,4 +81,34 @@ + (void)fetchDeferredAppLink:(FBSDKDeferredAppLinkHandler)handler
}];
}

+ (BOOL)fetchDeferredAppInvite:(FBSDKDeferredAppInviteHandler)handler
{
NSAssert([NSThread isMainThread], @"FBSDKAppLink fetchOrganicDeferredAppLink: must be invoked from main thread.");

NSAssert(handler, @"FBSDKAppLink fetchOrganicDeferredAppLink: must be invoked with valid handler.");

FBSDKOrganicDeeplinkHelper *deeplinkHelper = [[FBSDKOrganicDeeplinkHelper alloc] init];
return [deeplinkHelper fetchOrganicDeeplink:handler];
}

+ (NSString*)appInvitePromotionCodeFromURL:(NSURL*)url;
{
BFURL *parsedUrl = [[FBSDKInternalUtility resolveBoltsClassWithName:@"BFURL"] URLWithURL:url];
NSDictionary *extras = [parsedUrl appLinkExtras];
if (extras) {
NSString *deeplinkContextString = extras[@"deeplink_context"];

// Parse deeplinkContext and extract promo code
if ([deeplinkContextString length] > 0) {
NSError *error = nil;
NSDictionary *deeplinkContextData = [FBSDKInternalUtility objectForJSONString:deeplinkContextString error:&error];
if (!error && [deeplinkContextData isKindOfClass:[NSDictionary class]]) {
return deeplinkContextData[@"promo_code"];
}
}
}

return nil;

}
@end
Loading

0 comments on commit 4f4cdf4

Please sign in to comment.