Question

I'm using cordova facebook connect plugin for user authentication into my app. My problem is, I still don't know how to disable default error message if user cancel the login or share to facebook.

enter image description here

I already disable all alert message in facebook-js-sdk.js file, but still occurring.

Was it helpful?

Solution

Yes. It's working perfect.

Go to FacebookConnectPlugin.m file, find this function

- (void) showDialog:(CDVInvokedUrlCommand*)command

Replace with this code inside that function.

// Save the callback ID
    self.dialogCallbackId = command.callbackId;

    NSMutableDictionary *options = [[command.arguments lastObject] mutableCopy];
    NSString* method = [[NSString alloc] initWithString:[options objectForKey:@"method"]];
    if ([options objectForKey:@"method"]) {
        [options removeObjectForKey:@"method"];
    }
    __block BOOL paramsOK = YES;
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [options enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
        if ([obj isKindOfClass:[NSString class]]) {
            params[key] = obj;
        } else {
            NSError *error;
            NSData *jsonData = [NSJSONSerialization
                                dataWithJSONObject:obj
                                options:0
                                error:&error];
            if (!jsonData) {
                paramsOK = NO;
                // Error
                *stop = YES;
            }
            params[key] = [[NSString alloc]
                           initWithData:jsonData
                           encoding:NSUTF8StringEncoding];
        }
    }];

    if (!paramsOK) {
        CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
                                         messageAsString:@"Error completing dialog."];
        [self.commandDelegate sendPluginResult:pluginResult callbackId:self.dialogCallbackId];
    } else {
        // Show the web dialog
        [FBWebDialogs
         presentDialogModallyWithSession:FBSession.activeSession
         dialog:method parameters:params
         handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
             CDVPluginResult* pluginResult = nil;
             if (error) {
                 // Dialog failed with error
                 pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
                                                  messageAsString:@"Error completing dialog."];
             } else {
                 if (result == FBWebDialogResultDialogNotCompleted) {
                     // User clicked the "x" icon to Cancel
                     //pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
                                                      //messageAsString:@"User cancelled."];
                 } else {
                     // Send the URL parameters back, for a requests dialog, the "request" parameter
                     // will include the resluting request id. For a feed dialog, the "post_id"
                     // parameter will include the resulting post id.
                     NSDictionary *params = [self parseURLParams:[resultURL query]];
                     pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:params];
                 }
             }
             [self.commandDelegate sendPluginResult:pluginResult callbackId:self.dialogCallbackId];
         }];
        [super writeJavascript:nil];
    }

    // For optional ARC support
    #if __has_feature(objc_arc)
    #else
        [method release];
        [params release];
        [options release];
    #endif
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top