Skip to content

Commit

Permalink
Merge pull request #280 from hansemannn/feature/facebook-sdk-11.0.0
Browse files Browse the repository at this point in the history
feat(ios): update to Facebook SDK 13.1.0, support Apple Silicon / macOS, remove deprecated game request
  • Loading branch information
hansemannn authored Mar 25, 2022
2 parents 210c6ac + 3aa4316 commit 70277f6
Show file tree
Hide file tree
Showing 872 changed files with 51,056 additions and 8,565 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
126 changes: 29 additions & 97 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 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,64 +331,23 @@ - (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(
^{
[FBSDKAccessToken refreshCurrentAccessToken:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
[self fireEvent:@"tokenUpdated" withObject:nil];
[FBSDKAccessToken refreshCurrentAccessTokenWithCompletion:^(id<FBSDKGraphRequestConnecting> _Nullable connection, id _Nullable result, NSError * _Nullable error) {
[self fireEvent:@"tokenUpdated" withObject:@{ @"success": @(error == nil), @"error": NULL_IF_NIL(error.localizedDescription) }];
}];
},
NO);
Expand Down Expand Up @@ -540,7 +498,7 @@ - (void)requestWithGraphPath:(NSArray<id> *_Nonnull)args
^{
if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:path parameters:params HTTPMethod:httpMethod]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
startWithCompletion:^(id<FBSDKGraphRequestConnecting> _Nullable connection, id _Nullable result, NSError * _Nullable error) {
NSDictionary *returnedObject;
BOOL success = NO;

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

- (void)logEvents:(NSNotification *)notification
{
[FBSDKAppEvents 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
6 changes: 3 additions & 3 deletions ios/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 11.0.1
version: 12.0.0
apiversion: 2
description: Use the native Facebook iOS SDK in Axway Titanium.
author: Mark Mokryn, Ng Chee Kiat and Hans Knoechel
Expand All @@ -15,5 +15,5 @@ moduleid: facebook
guid: e4f7ac61-1ee7-44c5-bc27-fa6876e2dce9
platform: iphone
minsdk: 9.2.0
mac: false
architectures: armv7 arm64 i386 x86_64
mac: true
architectures: arm64 x86_64
Loading

0 comments on commit 70277f6

Please sign in to comment.