【问题标题】:PhoneGap iOS oAuth redirect failing (NSURLErrorDomain error -999.)PhoneGap iOS oAuth 重定向失败(NSURLErrorDomain 错误 -999。)
【发布时间】:2013-05-02 18:15:26
【问题描述】:

MeteorJS:https://github.com/zeroasterisk/Presenteract

PhoneGap:https://github.com/zeroasterisk/Presenteract-PhoneGap-ios

  • 我在 iOS 上的 PhoneGap 2.7 中运行 MeteorJS 应用程序。
  • MeteorJS 应用程序通过外部 URL 加载,在 config.xml 中设置为 <content src="http://presenteract.meteor.com" />
  • 我在浏览器中使用 oAuth 没有问题
  • access 配置使用完整的通配符 <access origin="*" />
  • 该应用程序运行良好,与它的浏览器版本相同....

但是当我在 PhoneGap 中尝试 oAuth 时,我会遇到以下错误:

Failed to load webpage with error: The operation couldn’t be completed.
(NSURLErrorDomain error -999.)

(注意:来自 Google、Facebook 和 Twitter 的 oAuth 尝试都是相同的。加载外部站点,登录正常进行,并在重定向回我的应用程序的主 URL 时)

我查看了其他 StackOverflow 报告并进行了一些谷歌搜索...我发现的最有用的是:

Facebook dialog failed with error: The operation couldn’t be completed. (NSURLErrorDomain error -999.) & 相关:NSURLErrorDomain error -999 - links failing in iOS

这看起来很有希望,但我不知道如何将这个解决方案翻译成PhoneGap...

我在<projectname>/Classes/MainViewController.m 中找到了以下存根,我已经用它玩了一下,但还没有解决方案....

- (void) webView:(UIWebView*)theWebView didFailLoadWithError:(NSError*)error
{
    /* (this does log to the console, but doesn't tell me anything different)
    * still: theWebView webView didFailLoadWithError:NSURLErrorDomain -999
    */
    NSLog(@"theWebView webView didFailLoadWithError:%@ %d",error.domain,error.code);

    /* (this is commented out, it didn't seem to do anything for me) */
    if ([error.domain isEqualToString:@"NSURLErrorDomain"] && error.code == -999) {
        NSLog(@"theWebView webView caught the error=-999... but returning void doesn't force the page to reload/continue:%@ %d",error.domain,error.code);
        return;
    }

    /* (this was already here, part of PhoneGap) */
    return [super webView:theWebView didFailLoadWithError:error];
}

我收到第二条“caught the error=-999”日志消息,但最终我仍然在应用程序上显示白屏。

  • 也许某处有一些设置允许重定向回我的应用程序的 URL?
  • 也许我需要强制它重新加载我应用的主页?
  • 也许我需要一些更优雅的方法来捕获错误,以便它不会停止加载?
  • 也许我首先需要有关导致失败的原因的更多信息?

【问题讨论】:

    标签: cordova oauth meteor


    【解决方案1】:

    我从 Cordova (PhoneGap) 2.2 升级到 2.7 时遇到了同样的错误。

    看你的描述,我不能轻易判断这是否是同一个问题。但是,我认为分享我的解决方案/解决方法可能会有所帮助。

    我遇到的问题是 Cordova 2.7 在启动期间没有正确处理客户端重定向。

    我也尝试过MainViewController.m,但我不相信这个问题可以在那里解决。

    我的解决方案是修改CordovaLib/Classes/CDVWebViewDelegate.m 来处理重定向情况。

    这是我的拉取请求:

    https://github.com/apache/cordova-ios/pull/57/files

    【讨论】:

    • 太棒了-感谢分享,我会尽快审查! (我正在玩弄“降级”PhoneGap 直到解决的想法,因为我也有不同的插件问题)
    • 修复了Phonegap 3.0的错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-22
    • 2013-12-30
    • 2013-04-11
    • 2014-03-07
    • 2020-03-01
    • 2017-03-14
    相关资源
    最近更新 更多