Skip to content

Commit

Permalink
feat: upgrade to Facebook iOS SDK 13.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hansemannn committed Mar 25, 2022
1 parent 00b89b0 commit 3aa4316
Show file tree
Hide file tree
Showing 1,257 changed files with 46,509 additions and 97,830 deletions.
18 changes: 1 addition & 17 deletions ios/Classes/Module/FacebookModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
/*!
@brief The root-namespace for the Facebook module
*/
@interface FacebookModule : TiModule <FBSDKSharingDelegate, FBSDKGameRequestDialogDelegate> {
@interface FacebookModule : TiModule <FBSDKSharingDelegate> {
NSString *_userID;
NSArray *_permissions;
NSNumber *_loginTracking;
Expand Down Expand Up @@ -358,22 +358,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)presentPhotoShareDialog:(NSArray<NSDictionary<NSString *, id> *> *_Nonnull)args;

/*!
@brief Build up and present a game request.
@param args The arguments passed to the send-request-dialog.
@code
const fb = require('facebook');
fb.presentSendRequestDialog({
title: 'New Game available',
message: 'Check this new game!'
});
@endcode
*/
- (void)presentSendRequestDialog:(NSArray<NSDictionary<NSString *, id> *> *_Nonnull)args;

/*!
@brief Refresh the current access token's permission state and extend the token's expiration date, if possible.
Expand Down
120 changes: 26 additions & 94 deletions ios/Classes/Module/FacebookModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ - (void)handleRelaunch:(NSNotification *_Nullable)notification
- (void)resumed:(id)note
{
[self handleRelaunch:nil];
[[FBSDKAppEvents singleton] activateApp];
[[FBSDKAppEvents shared] activateApp];
}

- (void)activateApp:(NSNotification *_Nullable)notification
Expand Down Expand Up @@ -96,12 +96,12 @@ - (NSNumber *_Nonnull)loggedIn

- (NSString *_Nonnull)appID
{
return [FBSDKSettings appID];
return FBSDKSettings.sharedSettings.appID;
}

- (void)setAppID:(NSString *_Nonnull)appID
{
[FBSDKSettings setAppID:[TiUtils stringValue:appID]];
FBSDKSettings.sharedSettings.appID = [TiUtils stringValue:appID];
}

- (NSArray<NSString *> *_Nullable)permissions
Expand Down Expand Up @@ -184,17 +184,17 @@ - (void)logPurchase:(NSArray<id> *_Nonnull)purchase
NSDictionary *parameters = [purchase objectAtIndex:2];
ENSURE_TYPE(parameters, NSDictionary);

[FBSDKAppEvents logPurchase:[amount doubleValue] currency:currency parameters:parameters];
[FBSDKAppEvents.shared logPurchase:[amount doubleValue] currency:currency parameters:parameters];
} else {
[FBSDKAppEvents logPurchase:[amount doubleValue] currency:currency];
[FBSDKAppEvents.shared logPurchase:[amount doubleValue] currency:currency];
}
}

- (void)logRegistrationCompleted:(NSString *_Nonnull)registrationMethod
{
NSDictionary *params = @{ FBSDKAppEventParameterNameRegistrationMethod : registrationMethod };

[FBSDKAppEvents logEvent:FBSDKAppEventNameCompletedRegistration parameters:params];
[FBSDKAppEvents.shared logEvent:FBSDKAppEventNameCompletedRegistration parameters:params];
}

- (void)logCustomEvent:(NSArray<id> *_Nonnull)customEvent
Expand All @@ -214,22 +214,22 @@ - (void)logCustomEvent:(NSArray<id> *_Nonnull)customEvent
ENSURE_SINGLE_ARG_OR_NIL(args2, NSDictionary);
NSDictionary *parameters = args2;

[FBSDKAppEvents logEvent:event valueToSum:valueToSum parameters:parameters];
[FBSDKAppEvents.shared logEvent:event valueToSum:valueToSum parameters:parameters];
}

- (void)logPushNotificationOpen:(NSArray<id> *_Nonnull)pushNotification
{
if ([pushNotification count] == 1) {
NSDictionary *payload = [pushNotification objectAtIndex:0];
[FBSDKAppEvents logPushNotificationOpen:payload];
[FBSDKAppEvents.shared logPushNotificationOpen:payload];
} else if ([pushNotification count] == 2) {
id payload = [pushNotification objectAtIndex:0];
id action = [pushNotification objectAtIndex:1];

ENSURE_TYPE(payload, NSDictionary);
ENSURE_TYPE(action, NSString);

[FBSDKAppEvents logPushNotificationOpen:payload action:action];
[FBSDKAppEvents.shared logPushNotificationOpen:payload action:action];
} else {
NSLog(@"[ERROR] Invalid number of arguments provided, please check the docs for 'logPushNotificationOpen' and try again!");
}
Expand All @@ -238,7 +238,7 @@ - (void)logPushNotificationOpen:(NSArray<id> *_Nonnull)pushNotification
- (void)setPushNotificationsDeviceToken:(NSString *_Nonnull)deviceToken
{
ENSURE_TYPE(deviceToken, NSString);
[FBSDKAppEvents setPushNotificationsDeviceToken:[FacebookModule dataFromHexString:deviceToken]];
[FBSDKAppEvents.shared setPushNotificationsDeviceToken:[FacebookModule dataFromHexString:deviceToken]];
}

- (void)authorize:(__unused id)unused
Expand Down Expand Up @@ -313,12 +313,11 @@ - (void)presentShareDialog:(NSArray<NSDictionary<NSString *, id> *> *_Nonnull)ar
TiThreadPerformOnMainThread(
^{
FBSDKShareLinkContent *content = [FacebookModule shareLinkContentFromDictionary:params];
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] initWithViewController:nil content:content delegate:self];

[dialog setMode:[TiUtils intValue:[params objectForKey:@"mode"] def:FBSDKShareDialogModeAutomatic]];
[dialog setFromViewController:nil];
[dialog setShareContent:content];
[dialog setDelegate:self];
if ([params objectForKey:@"mode"] != nil) {
dialog.mode = [TiUtils intValue:[params objectForKey:@"mode"] def:FBSDKShareDialogModeAutomatic];
}

[dialog show];
},
Expand All @@ -332,58 +331,17 @@ - (void)presentPhotoShareDialog:(NSArray<NSDictionary<NSString *, id> *> *_Nonnu
TiThreadPerformOnMainThread(
^{
FBSDKSharePhotoContent *content = [FacebookModule sharePhotoContentFromDictionary:params];
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] initWithViewController:nil content:content delegate:self];

[dialog setMode:[TiUtils intValue:[params objectForKey:@"mode"] def:FBSDKShareDialogModeAutomatic]];
[dialog setFromViewController:nil];
[dialog setShareContent:content];
[dialog setDelegate:self];
if ([params objectForKey:@"mode"] != nil) {
dialog.mode = [TiUtils intValue:[params objectForKey:@"mode"] def:FBSDKShareDialogModeAutomatic];
}

[dialog show];
},
NO);
}

- (void)presentSendRequestDialog:(NSArray<NSDictionary<NSString *, id> *> *)args
{
NSDictionary *_Nonnull params = [args objectAtIndex:0];

NSString *message = [params objectForKey:@"message"];
NSString *title = [params objectForKey:@"title"];
NSArray *recipients = [params objectForKey:@"recipients"];
NSArray *recipientSuggestions = [params objectForKey:@"recipientSuggestions"];
FBSDKGameRequestFilter filters = [TiUtils intValue:[params objectForKey:@"filters"]];
NSString *objectID = [params objectForKey:@"objectID"];
id tempData = [params objectForKey:@"data"];
NSString *data = nil;
if ([tempData isKindOfClass:[NSDictionary class]]) {
NSData *dictonaryData = [NSJSONSerialization dataWithJSONObject:tempData options:NSJSONWritingPrettyPrinted error:nil];
data = [[NSString alloc] initWithData:dictonaryData
encoding:NSUTF8StringEncoding];
} else {
data = (NSString *)tempData;
}

FBSDKGameRequestActionType actionType = [TiUtils intValue:[params objectForKey:@"actionType"]];

TiThreadPerformOnMainThread(
^{
FBSDKGameRequestContent *gameRequestContent = [[FBSDKGameRequestContent alloc] init];

gameRequestContent.title = title;
gameRequestContent.message = message;
gameRequestContent.recipients = recipients;
gameRequestContent.objectID = objectID;
gameRequestContent.data = data;
gameRequestContent.recipientSuggestions = recipientSuggestions;
gameRequestContent.filters = filters;
gameRequestContent.actionType = actionType;

[FBSDKGameRequestDialog showWithContent:gameRequestContent delegate:self];
},
NO);
}

- (void)refreshPermissionsFromServer:(__unused id)unused
{
TiThreadPerformOnMainThread(
Expand Down Expand Up @@ -682,7 +640,7 @@ - (void)fireLogin:(id _Nullable)result authenticationToken:(FBSDKAuthenticationT

- (void)logEvents:(NSNotification *)notification
{
[[FBSDKAppEvents singleton] activateApp];
[FBSDKAppEvents.shared activateApp];
}

- (void)accessTokenChanged:(NSNotification *)notification
Expand Down Expand Up @@ -719,23 +677,6 @@ - (void)sharerDidCancel:(id<FBSDKSharing>)sharer
[self fireDialogEventWithName:TiFacebookEventTypeShareCompleted andSuccess:NO error:nil cancelled:YES];
}

#pragma Game request delegates

- (void)gameRequestDialog:(FBSDKGameRequestDialog *)gameRequestDialog didCompleteWithResults:(NSDictionary *)results
{
[self fireDialogEventWithName:TiFacebookEventTypeRequestDialogCompleted andSuccess:YES error:nil cancelled:NO];
}

- (void)gameRequestDialog:(FBSDKGameRequestDialog *)gameRequestDialog didFailWithError:(NSError *)error
{
[self fireDialogEventWithName:TiFacebookEventTypeRequestDialogCompleted andSuccess:NO error:error cancelled:NO];
}

- (void)gameRequestDialogDidCancel:(FBSDKGameRequestDialog *)gameRequestDialog
{
[self fireDialogEventWithName:TiFacebookEventTypeRequestDialogCompleted andSuccess:NO error:nil cancelled:YES];
}

#pragma mark Dialog utilities

- (void)fireDialogEventWithName:(NSString *_Nonnull)name andSuccess:(BOOL)success error:(NSError *_Nullable)error cancelled:(BOOL)cancelled
Expand Down Expand Up @@ -809,7 +750,7 @@ + (FBSDKShareLinkContent *_Nonnull)shareLinkContentFromDictionary:(NSDictionary
[content setContentURL:link];

if (hashtag != nil) {
[content setHashtag:[FBSDKHashtag hashtagWithString:hashtag]];
[content setHashtag:[[FBSDKHashtag alloc] initWithString:hashtag]];
}

if (quote != nil) {
Expand Down Expand Up @@ -839,28 +780,28 @@ + (FBSDKSharePhotoContent *_Nonnull)sharePhotoContentFromDictionary:(NSDictionar
NSMutableArray<FBSDKSharePhoto *> *nativePhotos = [NSMutableArray arrayWithCapacity:photos.count];

for (NSDictionary<NSString *, id> *photoDictionary in photos) {
FBSDKSharePhoto *nativePhoto = nil;
id photo = photoDictionary[@"photo"];
NSString *caption = photoDictionary[@"caption"];
FBSDKSharePhoto *nativePhoto = [FBSDKSharePhoto new];
BOOL userGenerated = [TiUtils boolValue:photoDictionary[@"userGenerated"]];

// A photo can either be a Blob or String
if ([photo isKindOfClass:[TiBlob class]]) {
nativePhoto.image = [(TiBlob *)photo image];
UIImage *image = [(TiBlob *)photo image];
nativePhoto = [[FBSDKSharePhoto alloc] initWithImage:image isUserGenerated:userGenerated];
} else if ([photo isKindOfClass:[NSString class]]) {
nativePhoto.imageURL = [NSURL URLWithString:(NSString *)photo];
NSURL *imageURL = [NSURL URLWithString:(NSString *)photo];
nativePhoto = [[FBSDKSharePhoto alloc] initWithImageURL:imageURL isUserGenerated:userGenerated];
} else {
NSLog(@"[ERROR] Required \"photo\" not found or of unknown type: %@", NSStringFromClass([photo class]));
return;
}

// An optional caption
if (caption != nil) {
nativePhoto.caption = caption;
}

// An optional flag indicating if the photo was user generated
nativePhoto.userGenerated = userGenerated;

[nativePhotos addObject:nativePhoto];
}

Expand Down Expand Up @@ -896,15 +837,6 @@ + (NSData *)dataFromHexString:(NSString *)string
MAKE_SYSTEM_PROP(AUDIENCE_FRIENDS, FBSDKDefaultAudienceFriends);
MAKE_SYSTEM_PROP(AUDIENCE_EVERYONE, FBSDKDefaultAudienceEveryone);

MAKE_SYSTEM_PROP(ACTION_TYPE_NONE, FBSDKGameRequestActionTypeNone);
MAKE_SYSTEM_PROP(ACTION_TYPE_SEND, FBSDKGameRequestActionTypeSend);
MAKE_SYSTEM_PROP(ACTION_TYPE_ASK_FOR, FBSDKGameRequestActionTypeAskFor);
MAKE_SYSTEM_PROP(ACTION_TYPE_TURN, FBSDKGameRequestActionTypeTurn);

MAKE_SYSTEM_PROP(FILTER_NONE, FBSDKGameRequestFilterNone);
MAKE_SYSTEM_PROP(FILTER_APP_USERS, FBSDKGameRequestFilterAppUsers);
MAKE_SYSTEM_PROP(FILTER_APP_NON_USERS, FBSDKGameRequestFilterAppNonUsers);

MAKE_SYSTEM_PROP(MESSENGER_BUTTON_MODE_RECTANGULAR, TiFacebookShareButtonModeRectangular);
MAKE_SYSTEM_PROP(MESSENGER_BUTTON_MODE_CIRCULAR, TiFacebookShareButtonModeCircular);

Expand Down
46 changes: 12 additions & 34 deletions ios/platform/FBSDKCoreKit.xcframework/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,36 @@
<key>AvailableLibraries</key>
<array>
<dict>
<key>BitcodeSymbolMapsPath</key>
<string>BCSymbolMaps</string>
<key>DebugSymbolsPath</key>
<string>dSYMs</string>
<key>LibraryIdentifier</key>
<string>tvos-arm64</string>
<string>tvos-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>FBSDKCoreKit.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>tvos</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>BitcodeSymbolMapsPath</key>
<string>BCSymbolMaps</string>
<key>DebugSymbolsPath</key>
<string>dSYMs</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_armv7</string>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>FBSDKCoreKit.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>armv7</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>BitcodeSymbolMapsPath</key>
<string>BCSymbolMaps</string>
<key>DebugSymbolsPath</key>
<string>dSYMs</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-maccatalyst</string>
<key>LibraryPath</key>
Expand All @@ -57,43 +50,28 @@
<string>maccatalyst</string>
</dict>
<dict>
<key>BitcodeSymbolMapsPath</key>
<string>BCSymbolMaps</string>
<key>DebugSymbolsPath</key>
<string>dSYMs</string>
<key>LibraryIdentifier</key>
<string>tvos-arm64_x86_64-simulator</string>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>FBSDKCoreKit.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>tvos</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
<string>ios</string>
</dict>
<dict>
<key>BitcodeSymbolMapsPath</key>
<string>BCSymbolMaps</string>
<key>DebugSymbolsPath</key>
<string>dSYMs</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_i386_x86_64-simulator</string>
<string>tvos-arm64</string>
<key>LibraryPath</key>
<string>FBSDKCoreKit.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>i386</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
<string>tvos</string>
</dict>
</array>
<key>CFBundlePackageType</key>
Expand Down
Loading

0 comments on commit 3aa4316

Please sign in to comment.