From 76cfd4d4a3da87d8daa36ba6d9ff7a6addd7030f Mon Sep 17 00:00:00 2001 From: daviddalbusco Date: Sat, 21 Apr 2018 09:41:20 +0200 Subject: [PATCH] #645: Remove App Invites --- CHANGELOG.md | 4 ++ README.md | 39 -------------- src/android/ConnectPlugin.java | 94 --------------------------------- src/ios/FacebookConnectPlugin.h | 4 +- src/ios/FacebookConnectPlugin.m | 67 ----------------------- www/facebook-browser.js | 5 -- www/facebook-native.js | 5 -- 7 files changed, 6 insertions(+), 212 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51813aff5..0d7f1ad58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,12 @@ # [1.11.0](https://github.com/jeduan/cordova-plugin-facebook4/releases/tag/v1.11.0) (NOT RELEASED YET) +As of February 5, 2018, Facebook doesn't support anymore App Invites and new option for the Android installation. + ## Features +* **iOS:** App Invites support removed ([#645](https://github.com/jeduan/cordova-plugin-facebook4/issues/645)) + * **Android:** Add optional installation variable `ANDROID_SDK_VERSION` ([#550](https://github.com/jeduan/cordova-plugin-facebook4/issues/550))([#646](https://github.com/jeduan/cordova-plugin-facebook4/pull/646)) diff --git a/README.md b/README.md index c26fb981b..0f21a5528 100644 --- a/README.md +++ b/README.md @@ -219,45 +219,6 @@ Events are listed on the [insights page](https://www.facebook.com/insights/) `activateApp(Function success, Function failure)` -### App Invites - -`facebookConnectPlugin.appInvite(Object options, Function success, Function failure)` - -Please check out the [App Invites Overview](https://developers.facebook.com/docs/app-invites/overview) before using this. The URL is expected to be an [App Link](https://developers.facebook.com/docs/applinks). - -Example options: - - { - url: "http://example.com", - picture: "http://example.com/image.png" - } - -## Sample Code - -```js -facebookConnectPlugin.appInvite( - { - url: "http://example.com", - picture: "http://example.com/image.png" - }, - function(obj){ - if(obj) { - if(obj.completionGesture == "cancel") { - // user canceled, bad guy - } else { - // user really invited someone :) - } - } else { - // user just pressed done, bad guy - } - }, - function(obj){ - // error - console.log(obj); - } -); -``` - ### Login In your `onDeviceReady` event add the following diff --git a/src/android/ConnectPlugin.java b/src/android/ConnectPlugin.java index a612ac0a1..0401865af 100644 --- a/src/android/ConnectPlugin.java +++ b/src/android/ConnectPlugin.java @@ -29,11 +29,9 @@ import com.facebook.share.model.ShareOpenGraphObject; import com.facebook.share.model.ShareOpenGraphAction; import com.facebook.share.model.ShareOpenGraphContent; -import com.facebook.share.model.AppInviteContent; import com.facebook.share.widget.GameRequestDialog; import com.facebook.share.widget.MessageDialog; import com.facebook.share.widget.ShareDialog; -import com.facebook.share.widget.AppInviteDialog; import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaPlugin; @@ -77,7 +75,6 @@ public class ConnectPlugin extends CordovaPlugin { private String graphPath; private ShareDialog shareDialog; private GameRequestDialog gameRequestDialog; - private AppInviteDialog appInviteDialog; private MessageDialog messageDialog; @Override @@ -219,40 +216,6 @@ public void onError(FacebookException e) { handleError(e, showDialogContext); } }); - - appInviteDialog = new AppInviteDialog(cordova.getActivity()); - appInviteDialog.registerCallback(callbackManager, new FacebookCallback() { - @Override - public void onSuccess(AppInviteDialog.Result result) { - if (showDialogContext != null) { - try { - JSONObject json = new JSONObject(); - Bundle bundle = result.getData(); - for (String key : bundle.keySet()) { - json.put(key, wrapObject(bundle.get(key))); - } - - showDialogContext.success(json); - showDialogContext = null; - } catch (JSONException e) { - showDialogContext.success(); - showDialogContext = null; - } - } - } - - @Override - public void onCancel() { - FacebookOperationCanceledException e = new FacebookOperationCanceledException(); - handleError(e, showDialogContext); - } - - @Override - public void onError(FacebookException e) { - Log.e("Activity", String.format("Error: %s", e.toString())); - handleError(e, showDialogContext); - } - }); } @Override @@ -329,10 +292,6 @@ public boolean execute(String action, JSONArray args, final CallbackContext call } else if (action.equals("graphApi")) { executeGraph(args, callbackContext); - return true; - } else if (action.equals("appInvite")) { - executeAppInvite(args, callbackContext); - return true; } else if (action.equals("getDeferredApplink")) { executeGetDeferredApplink(args, callbackContext); @@ -370,59 +329,6 @@ public void onDeferredAppLinkDataFetched( }); } - private void executeAppInvite(JSONArray args, CallbackContext callbackContext) { - String url = null; - String picture = null; - JSONObject parameters; - - try { - parameters = args.getJSONObject(0); - } catch (JSONException e) { - parameters = new JSONObject(); - } - - if (parameters.has("url")) { - try { - url = parameters.getString("url"); - } catch (JSONException e) { - Log.e(TAG, "Non-string 'url' parameter provided to dialog"); - callbackContext.error("Incorrect 'url' parameter"); - return; - } - } else { - callbackContext.error("Missing required 'url' parameter"); - return; - } - - if (parameters.has("picture")) { - try { - picture = parameters.getString("picture"); - } catch (JSONException e) { - Log.e(TAG, "Non-string 'picture' parameter provided to dialog"); - callbackContext.error("Incorrect 'picture' parameter"); - return; - } - } - - if (AppInviteDialog.canShow()) { - AppInviteContent.Builder builder = new AppInviteContent.Builder(); - builder.setApplinkUrl(url); - if (picture != null) { - builder.setPreviewImageUrl(picture); - } - - showDialogContext = callbackContext; - PluginResult pr = new PluginResult(PluginResult.Status.NO_RESULT); - pr.setKeepCallback(true); - showDialogContext.sendPluginResult(pr); - - cordova.setActivityResultCallback(this); - appInviteDialog.show(builder.build()); - } else { - callbackContext.error("Unable to show dialog"); - } - } - private void executeDialog(JSONArray args, CallbackContext callbackContext) throws JSONException { Map params = new HashMap(); String method = null; diff --git a/src/ios/FacebookConnectPlugin.h b/src/ios/FacebookConnectPlugin.h index 37f2d9899..b316693b3 100644 --- a/src/ios/FacebookConnectPlugin.h +++ b/src/ios/FacebookConnectPlugin.h @@ -5,6 +5,7 @@ // Created by Jesse MacFadyen on 11-04-22. // Updated by Ally Ogilvie on 29/Jan/2014. // Updated by Jeduan Cornejo on 3/Jul/2015 +// Updated by David Dal Busco on 21/Apr/2018 - Facebook doesn't support App Invites anymore // Copyright 2011 Nitobi. All rights reserved. // @@ -15,7 +16,7 @@ #import #import "AppDelegate.h" -@interface FacebookConnectPlugin : CDVPlugin +@interface FacebookConnectPlugin : CDVPlugin - (void)getLoginStatus:(CDVInvokedUrlCommand *)command; - (void)getAccessToken:(CDVInvokedUrlCommand *)command; - (void)logEvent:(CDVInvokedUrlCommand *)command; @@ -25,7 +26,6 @@ - (void)logout:(CDVInvokedUrlCommand *)command; - (void)graphApi:(CDVInvokedUrlCommand *)command; - (void)showDialog:(CDVInvokedUrlCommand *)command; -- (void)appInvite:(CDVInvokedUrlCommand *) command; - (void)getDeferredApplink:(CDVInvokedUrlCommand *) command; - (void)activateApp:(CDVInvokedUrlCommand *)command; @end diff --git a/src/ios/FacebookConnectPlugin.m b/src/ios/FacebookConnectPlugin.m index c21b6ec44..fb728c341 100644 --- a/src/ios/FacebookConnectPlugin.m +++ b/src/ios/FacebookConnectPlugin.m @@ -476,33 +476,6 @@ - (void) graphApi:(CDVInvokedUrlCommand *)command }]; } -- (void) appInvite:(CDVInvokedUrlCommand *) command -{ - NSDictionary *options = [command.arguments objectAtIndex:0]; - NSString *url = options[@"url"]; - NSString *picture = options[@"picture"]; - CDVPluginResult *result; - self.dialogCallbackId = command.callbackId; - - FBSDKAppInviteContent *content = [[FBSDKAppInviteContent alloc] init]; - - if (url) { - content.appLinkURL = [NSURL URLWithString:url]; - } - if (picture) { - content.appInvitePreviewImageURL = [NSURL URLWithString:picture]; - } - - FBSDKAppInviteDialog *dialog = [[FBSDKAppInviteDialog alloc] init]; - if ((url || picture) && [dialog canShow]) { - [FBSDKAppInviteDialog showFromViewController:[self topMostController] withContent:content delegate:self]; - } else { - result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR]; - [self.commandDelegate sendPluginResult:result callbackId:self.dialogCallbackId]; - } - -} - - (void) getDeferredApplink:(CDVInvokedUrlCommand *) command { [FBSDKAppLinkUtility fetchDeferredAppLink:^(NSURL *url, NSError *error) { @@ -714,46 +687,6 @@ - (void)sharerDidCancel:(id)sharer { } -#pragma mark - FBSDKAppInviteDialogDelegate - -// add these methods in if you extend your sharing view controller with -- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didCompleteWithResults:(NSDictionary *)results -{ - - if (!self.dialogCallbackId) { - return; - } - - NSLog(@"app invite dialog did complete"); - NSLog(@"result::%@", results); - - CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK - messageAsDictionary:results]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:self.dialogCallbackId]; - self.dialogCallbackId = nil; - -} - - - -- (void)appInviteDialog:(FBSDKAppInviteDialog *)appInviteDialog didFailWithError:(NSError *)error -{ - if (!self.dialogCallbackId) { - return; - } - - NSLog(@"app invite dialog did fail"); - NSLog(@"error::%@", error); - - CDVPluginResult *pluginResult; - pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR - messageAsString:[NSString stringWithFormat:@"Error: %@", error.description]]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:self.dialogCallbackId]; - self.dialogCallbackId = nil; - -} - - #pragma mark - FBSDKGameRequestDialogDelegate - (void)gameRequestDialog:(FBSDKGameRequestDialog *)gameRequestDialog diff --git a/www/facebook-browser.js b/www/facebook-browser.js index dd97af3c4..bc3aaf45e 100644 --- a/www/facebook-browser.js +++ b/www/facebook-browser.js @@ -115,11 +115,6 @@ exports.logPurchase = function logPurchase (value, currency, s, f) { if(s) s(); } -exports.appInvite = function appInvite (options, s, f) { - // App Invites are not avaliable in JS. - if(s) s() -} - exports.logout = function logout (s, f) { if (!__fbSdkReady) { return __fbCallbacks.push(function() { diff --git a/www/facebook-native.js b/www/facebook-native.js index d8c1ce93a..456602832 100644 --- a/www/facebook-native.js +++ b/www/facebook-native.js @@ -46,11 +46,6 @@ exports.api = function api (graphPath, permissions, s, f) { exec(s, f, 'FacebookConnectPlugin', 'graphApi', [graphPath, permissions]) } -exports.appInvite = function appLinks (options, s, f) { - options = options || {} - exec(s, f, 'FacebookConnectPlugin', 'appInvite', [options]) -} - exports.getDeferredApplink = function (s, f) { exec(s, f, 'FacebookConnectPlugin', 'getDeferredApplink', []) }