默认错误消息 - 适用于iOS的Cordova Facebook Connect插件

时间:2014-05-14 03:47:37

标签: ios objective-c facebook cordova

我正在使用cordova facebook connect插件进行用户身份验证到我的应用中。我的问题是,如果用户取消登录或分享到Facebook,我仍然不知道如何禁用默认错误消息。

enter image description here

我已经在facebook-js-sdk.js文件中禁用了所有警报消息,但仍然发生。

1 个答案:

答案 0 :(得分:0)

是。它工作得很完美。

转到FacebookConnectPlugin.m文件,找到此功能

- (void) showDialog:(CDVInvokedUrlCommand*)command

在该函数中替换此代码。

// 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