Skip to content

Commit

Permalink
Update the Facebook SDK to 14 for Browser, Android and iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximBelov committed Sep 7, 2022
1 parent 3610ee2 commit dcd3f84
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 41 deletions.
7 changes: 4 additions & 3 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
<preference name="FACEBOOK_AUTO_LOG_APP_EVENTS" default="true" />
<preference name="FACEBOOK_HYBRID_APP_EVENTS" default="false" />
<preference name="FACEBOOK_ADVERTISER_ID_COLLECTION" default="true" />
<preference name="FACEBOOK_ANDROID_SDK_VERSION" default="12.0.0"/>
<preference name="FACEBOOK_IOS_SDK_VERSION" default="11.1.0"/>
<preference name="FACEBOOK_BROWSER_SDK_VERSION" default="v12.0" />
<preference name="FACEBOOK_ANDROID_SDK_VERSION" default="14.1.1"/>
<preference name="FACEBOOK_IOS_SDK_VERSION" default="14.1.0"/>
<preference name="FACEBOOK_BROWSER_SDK_VERSION" default="v14.0" />

<engines>
<engine name="cordova-android" version=">=9.0.0" />
Expand Down Expand Up @@ -199,6 +199,7 @@
<pod name="FBSDKCoreKit" spec="$FACEBOOK_IOS_SDK_VERSION"/>
<pod name="FBSDKLoginKit" spec="$FACEBOOK_IOS_SDK_VERSION"/>
<pod name="FBSDKShareKit" spec="$FACEBOOK_IOS_SDK_VERSION"/>
<pod name="FBSDKGamingServicesKit" spec="$FACEBOOK_IOS_SDK_VERSION"/>
</pods>
</podspec>

Expand Down
1 change: 1 addition & 0 deletions src/ios/FacebookConnectPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
#import <FBSDKShareKit/FBSDKShareKit.h>
#import <FBSDKGamingServicesKit/FBSDKGamingServicesKit-Swift.h>
#import <Cordova/CDV.h>
#import "AppDelegate.h"

Expand Down
102 changes: 64 additions & 38 deletions src/ios/FacebookConnectPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ - (void)pluginInitialize {
selector:@selector(applicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleOpenURLWithAppSourceAndAnnotation:)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleOpenURLWithAppSourceAndAnnotation:)
name:CDVPluginHandleOpenURLWithAppSourceAndAnnotationNotification object:nil];
}

Expand All @@ -59,8 +59,8 @@ - (void) applicationDidFinishLaunching:(NSNotification *) notification {
}

- (void) applicationDidBecomeActive:(NSNotification *) notification {
if (FBSDKSettings.isAutoLogAppEventsEnabled) {
[FBSDKAppEvents activateApp];
if (FBSDKSettings.sharedSettings.isAutoLogAppEventsEnabled) {
[FBSDKAppEvents.shared activateApp];
}
if (self.applicationWasActivated == NO) {
self.applicationWasActivated = YES;
Expand All @@ -78,7 +78,7 @@ - (void) handleOpenURLWithAppSourceAndAnnotation:(NSNotification *) notification
#pragma mark - Cordova commands

- (void)getApplicationId:(CDVInvokedUrlCommand *)command {
NSString *appID = FBSDKSettings.appID;
NSString *appID = FBSDKSettings.sharedSettings.appID;
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:appID];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
Expand All @@ -91,12 +91,12 @@ - (void)setApplicationId:(CDVInvokedUrlCommand *)command {
}

NSString *appId = [command argumentAtIndex:0];
[FBSDKSettings setAppID:appId];
[FBSDKSettings.sharedSettings setAppID:appId];
[self returnGenericSuccess:command.callbackId];
}

- (void)getClientToken:(CDVInvokedUrlCommand *)command {
NSString *clientToken = FBSDKSettings.clientToken;
NSString *clientToken = FBSDKSettings.sharedSettings.clientToken;
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:clientToken];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
Expand All @@ -109,12 +109,12 @@ - (void)setClientToken:(CDVInvokedUrlCommand *)command {
}

NSString *clientToken = [command argumentAtIndex:0];
[FBSDKSettings setClientToken:clientToken];
[FBSDKSettings.sharedSettings setClientToken:clientToken];
[self returnGenericSuccess:command.callbackId];
}

- (void)getApplicationName:(CDVInvokedUrlCommand *)command {
NSString *displayName = FBSDKSettings.displayName;
NSString *displayName = FBSDKSettings.sharedSettings.displayName;
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:displayName];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
Expand All @@ -127,7 +127,7 @@ - (void)setApplicationName:(CDVInvokedUrlCommand *)command {
}

NSString *displayName = [command argumentAtIndex:0];
[FBSDKSettings setDisplayName:displayName];
[FBSDKSettings.sharedSettings setDisplayName:displayName];
[self returnGenericSuccess:command.callbackId];
}

Expand All @@ -139,7 +139,7 @@ - (void)getLoginStatus:(CDVInvokedUrlCommand *)command {

BOOL force = [[command argumentAtIndex:0] boolValue];
if (force) {
[FBSDKAccessToken refreshCurrentAccessToken:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
[FBSDKAccessToken refreshCurrentAccessTokenWithCompletion:^(id<FBSDKGraphRequestConnecting> _Nullable connection, id _Nullable result, NSError * _Nullable error) {
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsDictionary:[self loginResponseObject]];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
Expand Down Expand Up @@ -172,19 +172,19 @@ - (void)getAccessToken:(CDVInvokedUrlCommand *)command {

- (void)setAutoLogAppEventsEnabled:(CDVInvokedUrlCommand *)command {
BOOL enabled = [[command argumentAtIndex:0] boolValue];
[FBSDKSettings setAutoLogAppEventsEnabled:enabled];
[FBSDKSettings.sharedSettings setAutoLogAppEventsEnabled:enabled];
[self returnGenericSuccess:command.callbackId];
}

- (void)setAdvertiserIDCollectionEnabled:(CDVInvokedUrlCommand *)command {
BOOL enabled = [[command argumentAtIndex:0] boolValue];
[FBSDKSettings setAdvertiserIDCollectionEnabled:enabled];
[FBSDKSettings.sharedSettings setAdvertiserIDCollectionEnabled:enabled];
[self returnGenericSuccess:command.callbackId];
}

- (void)setAdvertiserTrackingEnabled:(CDVInvokedUrlCommand *)command {
BOOL enabled = [[command argumentAtIndex:0] boolValue];
[FBSDKSettings setAdvertiserTrackingEnabled:enabled];
[FBSDKSettings.sharedSettings setAdvertiserTrackingEnabled:enabled];
[self returnGenericSuccess:command.callbackId];
}

Expand All @@ -197,11 +197,11 @@ - (void)setDataProcessingOptions:(CDVInvokedUrlCommand *)command {

NSArray *options = [command argumentAtIndex:0];
if ([command.arguments count] == 1) {
[FBSDKSettings setDataProcessingOptions:options];
[FBSDKSettings.sharedSettings setDataProcessingOptions:options];
} else {
NSString *country = [command.arguments objectAtIndex:1];
NSString *state = [command.arguments objectAtIndex:2];
[FBSDKSettings setDataProcessingOptions:options country:country state:state];
[FBSDKSettings.sharedSettings setDataProcessingOptions:options country:country state:state];
}
[self returnGenericSuccess:command.callbackId];
}
Expand All @@ -221,7 +221,7 @@ - (void)setUserData:(CDVInvokedUrlCommand *)command {
[self.commandDelegate sendPluginResult:res callbackId:command.callbackId];
return;
} else {
[FBSDKAppEvents setUserEmail:(NSString *)params[@"em"]
[FBSDKAppEvents.shared setUserEmail:(NSString *)params[@"em"]
firstName:(NSString*)params[@"fn"]
lastName:(NSString *)params[@"ln"]
phone:(NSString *)params[@"ph"]
Expand All @@ -238,7 +238,7 @@ - (void)setUserData:(CDVInvokedUrlCommand *)command {
}

- (void)clearUserData:(CDVInvokedUrlCommand *)command {
[FBSDKAppEvents clearUserData];
[FBSDKAppEvents.shared clearUserData];
[self returnGenericSuccess:command.callbackId];
}

Expand All @@ -257,20 +257,20 @@ - (void)logEvent:(CDVInvokedUrlCommand *)command {
double value;

if ([command.arguments count] == 1) {
[FBSDKAppEvents logEvent:eventName];
[FBSDKAppEvents.shared logEvent:eventName];

} else {
// argument count is not 0 or 1, must be 2 or more
params = [command.arguments objectAtIndex:1];
if ([command.arguments count] == 2) {
// If count is 2 we will just send params
[FBSDKAppEvents logEvent:eventName parameters:params];
[FBSDKAppEvents.shared logEvent:eventName parameters:params];
}

if ([command.arguments count] >= 3) {
// If count is 3 we will send params and a value to sum
value = [[command.arguments objectAtIndex:2] doubleValue];
[FBSDKAppEvents logEvent:eventName valueToSum:value parameters:params];
[FBSDKAppEvents.shared logEvent:eventName valueToSum:value parameters:params];
}
}
[self returnGenericSuccess:command.callbackId];
Expand All @@ -288,10 +288,10 @@ - (void)logPurchase:(CDVInvokedUrlCommand *)command {
NSString *currency = [command.arguments objectAtIndex:1];

if ([command.arguments count] == 2 ) {
[FBSDKAppEvents logPurchase:value currency:currency];
[FBSDKAppEvents.shared logPurchase:value currency:currency];
} else if ([command.arguments count] >= 3) {
NSDictionary *params = [command.arguments objectAtIndex:2];
[FBSDKAppEvents logPurchase:value currency:currency parameters:params];
[FBSDKAppEvents.shared logPurchase:value currency:currency parameters:params];
}

[self returnGenericSuccess:command.callbackId];
Expand All @@ -309,7 +309,7 @@ - (void)login:(CDVInvokedUrlCommand *)command {

// this will prevent from being unable to login after updating plugin or changing permissions
// without refreshing there will be a cache problem. This simple call should fix the problems
[FBSDKAccessToken refreshCurrentAccessToken:nil];
[FBSDKAccessToken refreshCurrentAccessTokenWithCompletion:nil];

FBSDKLoginManagerLoginResultBlock loginHandler = ^void(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
Expand Down Expand Up @@ -413,20 +413,20 @@ - (void) checkHasCorrectPermissions:(CDVInvokedUrlCommand*)command
permissions = command.arguments;
}

NSSet *grantedPermissions = [FBSDKAccessToken currentAccessToken].permissions;
NSSet *grantedPermissions = [FBSDKAccessToken currentAccessToken].permissions;

for (NSString *value in permissions) {
NSLog(@"Checking permission %@.", value);
NSLog(@"Checking permission %@.", value);
if (![grantedPermissions containsObject:value]) { //checks if permissions does not exists
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
messageAsString:@"A permission has been denied"];
messageAsString:@"A permission has been denied"];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
return;
}
}

CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsString:@"All permissions have been accepted"];
messageAsString:@"All permissions have been accepted"];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
return;
}
Expand Down Expand Up @@ -529,10 +529,10 @@ - (void) showDialog:(CDVInvokedUrlCommand*)command
} else if ([method isEqualToString:@"share"] || [method isEqualToString:@"feed"]) {
// Create native params
self.dialogCallbackId = command.callbackId;
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
FBSDKShareDialog *dialog = [FBSDKShareDialog alloc];
dialog.fromViewController = [self topMostController];
if (params[@"photo_image"]) {
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
FBSDKSharePhoto *photo = [FBSDKSharePhoto alloc];
NSString *photoImage = params[@"photo_image"];
if (![photoImage isKindOfClass:[NSString class]]) {
NSLog(@"photo_image must be a string");
Expand All @@ -542,7 +542,7 @@ - (void) showDialog:(CDVInvokedUrlCommand*)command
NSLog(@"photo_image cannot be decoded");
} else {
photo.image = [UIImage imageWithData:photoImageData];
photo.userGenerated = YES;
photo.isUserGenerated = YES;
}
}
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
Expand All @@ -551,7 +551,7 @@ - (void) showDialog:(CDVInvokedUrlCommand*)command
} else {
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:params[@"href"]];
content.hashtag = [FBSDKHashtag hashtagWithString:[params objectForKey:@"hashtag"]];
content.hashtag = [[FBSDKHashtag alloc] initWithString:[params objectForKey:@"hashtag"]];
content.quote = params[@"quote"];
dialog.shareContent = content;
}
Expand All @@ -571,7 +571,7 @@ - (void) showDialog:(CDVInvokedUrlCommand*)command
return;
}
else if ([method isEqualToString:@"apprequests"]) {
FBSDKGameRequestDialog *dialog = [[FBSDKGameRequestDialog alloc] init];
FBSDKGameRequestDialog *dialog = [FBSDKGameRequestDialog alloc];
dialog.delegate = self;
if (![dialog canShow]) {
CDVPluginResult *pluginResult;
Expand All @@ -580,7 +580,7 @@ - (void) showDialog:(CDVInvokedUrlCommand*)command
return;
}

FBSDKGameRequestContent *content = [[FBSDKGameRequestContent alloc] init];
FBSDKGameRequestContent *content = [FBSDKGameRequestContent alloc];
NSString *actionType = params[@"actionType"];
if (!actionType) {
NSLog(@"Discarding invalid argument actionType");
Expand Down Expand Up @@ -690,7 +690,20 @@ - (void) graphApi:(CDVInvokedUrlCommand *)command

// If we have permissions to request
if ([permissions count] == 0){
[request startWithCompletionHandler:graphHandler];
[request startWithCompletion:^(id<FBSDKGraphRequestConnecting> _Nullable connection, id _Nullable result, NSError * _Nullable error) {
CDVPluginResult* pluginResult;
if (error) {
NSString *message = error.userInfo[FBSDKErrorLocalizedDescriptionKey] ?: @"There was an error making the graph call.";
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
messageAsString:message];
} else {
NSDictionary *response = (NSDictionary *) result;
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:response];
}
NSLog(@"Finished GraphAPI request");

[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
return;
}

Expand Down Expand Up @@ -724,7 +737,20 @@ - (void) graphApi:(CDVInvokedUrlCommand *)command
return;
}

[request startWithCompletionHandler:graphHandler];
[request startWithCompletion:^(id<FBSDKGraphRequestConnecting> _Nullable connection, id _Nullable result, NSError * _Nullable error) {
CDVPluginResult* pluginResult;
if (error) {
NSString *message = error.userInfo[FBSDKErrorLocalizedDescriptionKey] ?: @"There was an error making the graph call.";
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
messageAsString:message];
} else {
NSDictionary *response = (NSDictionary *) result;
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:response];
}
NSLog(@"Finished GraphAPI request");

[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}];
}

Expand All @@ -750,7 +776,7 @@ - (void) getDeferredApplink:(CDVInvokedUrlCommand *) command

- (void) activateApp:(CDVInvokedUrlCommand *)command
{
[FBSDKAppEvents activateApp];
[FBSDKAppEvents.shared activateApp];
[self returnGenericSuccess:command.callbackId];
}

Expand Down Expand Up @@ -896,7 +922,7 @@ - (void)enableHybridAppEvents {
if ([self.webView isMemberOfClass:[WKWebView class]]){
NSString *is_enabled = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"FacebookHybridAppEvents"];
if([is_enabled isEqualToString:@"true"]){
[FBSDKAppEvents augmentHybridWKWebView:(WKWebView*)self.webView];
[FBSDKAppEvents.shared augmentHybridWebView:(WKWebView*)self.webView];
NSLog(@"FB Hybrid app events are enabled");
} else {
NSLog(@"FB Hybrid app events are not enabled");
Expand Down

0 comments on commit dcd3f84

Please sign in to comment.