Skip to content

Instantly share code, notes, and snippets.

@scottmkroberts
Last active November 25, 2016 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottmkroberts/18e118bbee026d75599781b46cedaf0b to your computer and use it in GitHub Desktop.
Save scottmkroberts/18e118bbee026d75599781b46cedaf0b to your computer and use it in GitHub Desktop.
ionic FacebookConnectPlugin Addition
/**
*The following mimics thefunctionality of showDialog in how to call the function but instead of using the method
* to know what dialog to show we use the passed method name to check for that permssion e.g. "email".
*/
// In www/facebook-native.js
exports.checkPermissions = function checkPermissions (options, s, f) {
exec(s, f, 'FacebookConnectPlugin', 'checkPermissions', [options])
}
// In src/ios/FacebookConnectPlugin.h
- (void) checkPermissions:(CDVInvokedUrlCommand*)command
// In src/ios/FacebookConnectPlugin.m
-(void) checkPermissions:(CDVInvokedUrlCommand*)command
{
//["email","user_friends","user_likes","user_birthday","user_photos”]
if ([command.arguments count] == 0) {
CDVPluginResult *pluginResult;
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
messageAsString:@"No method provided"];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
return;
}
NSMutableDictionary *options = [[command.arguments lastObject] mutableCopy];
NSString* method = options[@"method"];
if (!method) {
CDVPluginResult *pluginResult;
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
messageAsString:@"No method provided"];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
return;
}
[options removeObjectForKey:@"method"];
NSDictionary *params = [options copy];
NSSet *grantedPermissions = [FBSDKAccessToken currentAccessToken].permissions; //gets current list of permissions
for (NSString* key in params) {
NSString value = [xyz objectForKey:key];
if !([grantedPermissions containsObject:value]) { //checks if permissions exists
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
return;
}
}
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment