Skip to content

Instantly share code, notes, and snippets.

@scottmkroberts
Last active November 25, 2016 23:23
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/aeab294fc5457532f5dc462a6994dfe4 to your computer and use it in GitHub Desktop.
Save scottmkroberts/aeab294fc5457532f5dc462a6994dfe4 to your computer and use it in GitHub Desktop.
Facebook auto check
/**
*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.checkHasCorrectPermissions = function checkHasCorrectPermissions (s, f) {
exec(s, f, 'FacebookConnectPlugin', 'checkHasCorrectPermissions', [])
}
// In src/ios/FacebookConnectPlugin.h
- (void) checkHasCorrectPermissions:(CDVInvokedUrlCommand*)command
// In src/ios/FacebookConnectPlugin.m
- (void) checkHasCorrectPermissions:(CDVInvokedUrlCommand*)command{
NSArray *permissions = ["email","user_friends","user_likes","user_birthday","user_photos"];
NSSet *grantedPermissions = [FBSDKAccessToken currentAccessToken].permissions; //gets current list of permissions
for (NSString value in permissions) {
if !([grantedPermissions containsObject:value]) { //checks if permissions does not 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