Skip to content

Commit

Permalink
jeduan#645: Remove App Invites
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpeterparker committed Apr 21, 2018
1 parent ef24d20 commit 336616f
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 212 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<a name="1.11.0"></a>
# [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))

<a name="1.10.1"></a>
Expand Down
39 changes: 0 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
94 changes: 0 additions & 94 deletions src/android/ConnectPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -219,40 +216,6 @@ public void onError(FacebookException e) {
handleError(e, showDialogContext);
}
});

appInviteDialog = new AppInviteDialog(cordova.getActivity());
appInviteDialog.registerCallback(callbackManager, new FacebookCallback<AppInviteDialog.Result>() {
@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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<String, String> params = new HashMap<String, String>();
String method = null;
Expand Down
4 changes: 2 additions & 2 deletions src/ios/FacebookConnectPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//

Expand All @@ -15,7 +16,7 @@
#import <Cordova/CDV.h>
#import "AppDelegate.h"

@interface FacebookConnectPlugin : CDVPlugin <FBSDKSharingDelegate, FBSDKAppInviteDialogDelegate, FBSDKGameRequestDialogDelegate>
@interface FacebookConnectPlugin : CDVPlugin <FBSDKSharingDelegate, FBSDKGameRequestDialogDelegate>
- (void)getLoginStatus:(CDVInvokedUrlCommand *)command;
- (void)getAccessToken:(CDVInvokedUrlCommand *)command;
- (void)logEvent:(CDVInvokedUrlCommand *)command;
Expand All @@ -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
67 changes: 0 additions & 67 deletions src/ios/FacebookConnectPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -714,46 +687,6 @@ - (void)sharerDidCancel:(id<FBSDKSharing>)sharer {
}


#pragma mark - FBSDKAppInviteDialogDelegate

// add these methods in if you extend your sharing view controller with <FBSDKAppInviteDialogDelegate>
- (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
Expand Down
5 changes: 0 additions & 5 deletions www/facebook-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 0 additions & 5 deletions www/facebook-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', [])
}
Expand Down

0 comments on commit 336616f

Please sign in to comment.