javascript - Cordova/Phonegap oauth.io 弹出窗口未显示

标签 javascript ios cordova oauth

我正在开发一个 cordova 网络应用程序,实际上我集成了 oauth.io API 并且我使用自己的服务器守护进程来使其工作。

当我尝试在桌面浏览器上通过社交登录时,它就像一个魅力,但当我尝试在 ios 模拟器上它不会工作,它不会打开弹出窗口以通过社交连接。

所以我安装了这个 https://github.com/oauth-io/oauth-phonegap更改 config.xml 文件以允许所有源以这种方式:

    .....
     <content src="index.html" />
    <access origin="*" />
    <preference name="webviewbounce" value="false" />
    <preference name="UIWebViewBounce" value="false" />
    <preference name="DisallowOverscroll" value="true" />

    <!-- Don't store local date in an iCloud backup. Turn this to "cloud" to enable storage
         to be sent to iCloud. Note: enabling this could result in Apple rejecting your app.
    -->
    <preference name="BackupWebStorage" value="none" />
    <feature name="StatusBar">
      <param name="ios-package" value="CDVStatusBar" onload="true" />
    </feature>
    <feature name="InAppBrowser">
       <param name="ios-package" value="CDVInAppBrowser" />
    </feature>
.....

我使用 ionicframework,所以我的 oauth 代码是 javascript/angularjs,我可以在这里显示:

 .provider('OAuthd', function () {

    var theClientId = '';

    return {

      'setClientId': function(value) {
        theClientId = value;
      },
      '$get': ['$window', '$q', '$cacheFactory', function ($window, $q, $cacheFactory) {

        var cache = $cacheFactory('OAuthdProviderCache');
        ($window.OAuth.initialize || angular.noop)(theClientId);

        return {
          'facebook' : function() {

            var facebookAPI = cache.get('facebook')
              , deferred = $q.defer();

            if (!facebookAPI) {

              $window.OAuth.popup('facebook', function(err, result) {

                if (!err) {

                  deferred.resolve(result);
                } else {

                  deferred.reject(err);
                }
              });
              cache.put('facebook', deferred.promise);
              return deferred.promise;
            }

            return facebookAPI;
          },
          'twitter': function() {

            var twitterAPI = cache.get('twitter')
              , deferred = $q.defer();

            if (!twitterAPI) {

              $window.OAuth.popup('twitter', function(err, result) {

                if (!err) {

                  deferred.resolve(result);
                } else {

                  deferred.reject(err);
                }
              });
              cache.put('twitter', deferred.promise);
              return deferred.promise;
            }

            return twitterAPI;
          },
          'google': function() {

            var googlePlusAPI = cache.get('google_plus')
              , deferred = $q.defer();

            if (!googlePlusAPI) {

              $window.OAuth.popup('google_plus', function(err, result) {

                if (!err) {

                  deferred.resolve(result);
                } else {

                  deferred.reject(err);
                }
              });

              cache.put('google_plus', deferred.promise);
              return deferred.promise;
            }

            return googlePlusAPI;
          }
        };
      }]
    };
});

但无论如何都行不通,你有什么线索吗?

谢谢

这是每次我在 ios 模拟器或 android 模拟器上尝试时 cordova console.log 返回的内容:

Terminating in response to SpringBoard's termination.
2014-08-08 11:18:53.958 chatting[4573:70b] Multi-tasking -> Device: YES, App: YES
2014-08-08 11:18:53.971 chatting[4573:70b] Unlimited access to network resources
2014-08-08 11:18:54.000 chatting[4573:70b] CDVPlugin class IonicKeyboard (pluginName: keyboard) does not exist.
2014-08-08 11:18:54.000 chatting[4573:70b] [CDVTimer][keyboard] 0.589967ms
2014-08-08 11:18:54.001 chatting[4573:70b] CDVPlugin class CDVStatusBar (pluginName: statusbar) does not exist.
2014-08-08 11:18:54.002 chatting[4573:70b] [CDVTimer][statusbar] 0.699997ms
2014-08-08 11:18:54.002 chatting[4573:70b] [CDVTimer][TotalPluginStartup] 2.420008ms
2014-08-08 11:18:54.351 chatting[4573:70b] Resetting plugins due to page load.
2014-08-08 11:18:55.026 chatting[4573:70b] Finished load of: file:///Users/macuser/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/CA5E4763-35DA-44A3-A907-77E58E4CB181/chatting.app/www/index.html#/app/home
2014-08-08 11:18:55.274 chatting[4573:70b] CDVPlugin class IonicKeyboard (pluginName: Keyboard) does not exist.
2014-08-08 11:18:55.275 chatting[4573:70b] ERROR: Plugin 'Keyboard' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
2014-08-08 11:18:55.275 chatting[4573:70b] -[CDVCommandQueue executePending] [Line 158] FAILED pluginJSON = [
  "INVALID",
  "Keyboard",
  "hideKeyboardAccessoryBar",
  [
    true
  ]
]
2014-08-08 11:19:06.985 chatting[4573:70b] CDVPlugin class CDVInAppBrowser (pluginName: InAppBrowser) does not exist.
2014-08-08 11:19:06.985 chatting[4573:70b] ERROR: Plugin 'InAppBrowser' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
2014-08-08 11:19:06.986 chatting[4573:70b] -[CDVCommandQueue executePending] [Line 158] FAILED pluginJSON = [
  "InAppBrowser1514682083",
  "InAppBrowser",
  "open",
  [
    "http:\/\/auth.mysite.eu\/auth\/facebook?k=Jnpo3LK9wWrScy_cZ5xOQ5Fctx4&d=file%3A%2F%2F%2F&opts=%7B%22state%22%3A%222A9nV3-_ZBGs8HbZKVn_ffmy5MA%22%2C%22state_type%22%3A%22client%22%7D",
    "Authorization",
    "width=800,height=350,toolbar=0,scrollbars=1,status=1,resizable=1,location=1,menuBar=0,left=-240,top=16.25"
  ]
]
2014-08-08 11:19:06.987 chatting[4573:70b] CDVPlugin class CDVLogger (pluginName: Console) does not exist.
2014-08-08 11:19:06.988 chatting[4573:70b] ERROR: Plugin 'Console' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
2014-08-08 11:19:06.988 chatting[4573:70b] -[CDVCommandQueue executePending] [Line 158] FAILED pluginJSON = [
  "INVALID",
  "Console",
  "logLevel",
  [
    "ERROR",
    "Error: 'undefined' is not a function (evaluating 'wnd.focus()')\npopup@http:\/\/auth.mysite.eu\/download\/latest\/oauth.js:323:15\nfacebook@file:\/\/\/Users\/macuser\/Library\/Application%20Support\/iPhone%20Simulator\/7.1\/Applications\/CA5E4763-35DA-44A3-A907-77E58E4CB181\/chatting.app\/www\/assets\/js\/providers.js:27:34\nsignup@file:\/\/\/Users\/macuser\/Library\/Application%20Support\/iPhone%20Simulator\/7.1\/Applications\/CA5E4763-35DA-44A3-A907-77E58E4CB181\/chatting.app\/www\/assets\/js\/controllers.js:91:24\nfile:\/\/\/Users\/macuser\/Library\/Application%20Support\/iPhone%20Simulator\/7.1\/Applications\/CA5E4763-35DA-44A3-A907-77E58E4CB181\/chatting.app\/www\/lib\/ionic\/js\/ionic.bundle.js:19654:26\nfile:\/\/\/Users\/macuser\/Library\/Application%20Support\/iPhone%20Simulator\/7.1\/Applications\/CA5E4763-35DA-44A3-A907-77E58E4CB181\/chatting.app\/www\/lib\/ionic\/js\/ionic.bundle.js:42758:21\n$eval@file:\/\/\/Users\/macuser\/Library\/Application%20Support[...]
2014-08-08 18:12:18.174 chatting[7825:70b] Multi-tasking -> Device: YES, App: YES
2014-08-08 18:12:31.794 chatting[7825:70b] Unlimited access to network resources
2014-08-08 18:12:49.439 chatting[7825:70b] CDVPlugin class IonicKeyboard (pluginName: keyboard) does not exist.
2014-08-08 18:12:49.440 chatting[7825:70b] [CDVTimer][keyboard] 0.704050ms
2014-08-08 18:12:49.440 chatting[7825:70b] CDVPlugin class CDVStatusBar (pluginName: statusbar) does not exist.
2014-08-08 18:12:49.441 chatting[7825:70b] [CDVTimer][statusbar] 0.515997ms
2014-08-08 18:12:49.441 chatting[7825:70b] [CDVTimer][TotalPluginStartup] 2.322972ms
2014-08-08 18:12:54.431 chatting[7825:70b] Resetting plugins due to page load.
2014-08-08 18:13:06.581 chatting[7825:70b] Finished load of: file:///Users/macuser/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/CA5E4763-35DA-44A3-A907-77E58E4CB181/chatting.app/www/index.html#/app/home
2014-08-08 18:13:08.127 chatting[7825:70b] CDVPlugin class IonicKeyboard (pluginName: Keyboard) does not exist.
2014-08-08 18:13:08.127 chatting[7825:70b] ERROR: Plugin 'Keyboard' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
2014-08-08 18:13:08.127 chatting[7825:70b] -[CDVCommandQueue executePending] [Line 158] FAILED pluginJSON = [
  "INVALID",
  "Keyboard",
  "hideKeyboardAccessoryBar",
  [
    true
  ]
]
2014-08-08 18:14:37.227 chatting[7825:70b] CDVPlugin class CDVInAppBrowser (pluginName: InAppBrowser) does not exist.
2014-08-08 18:14:37.228 chatting[7825:70b] ERROR: Plugin 'InAppBrowser' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
2014-08-08 18:14:37.228 chatting[7825:70b] -[CDVCommandQueue executePending] [Line 158] FAILED pluginJSON = [
  "InAppBrowser1564421013",
  "InAppBrowser",
  "open",
  [
    "http:\/\/auth.mysite.eu\/auth\/facebook?k=Jnpo3LK9wWrScy_cZ5xOQ5Fctx4&d=file%3A%2F%2F%2F&opts=%7B%22state%22%3A%226EG62ptFFZVSaIg2e2QCZXYx5Ak%22%2C%22state_type%22%3A%22client%22%7D",
    "Authorization",
    "width=800,height=350,toolbar=0,scrollbars=1,status=1,resizable=1,location=1,menuBar=0,left=-240,top=16.25"
  ]
]
2014-08-08 18:14:37.229 chatting[7825:70b] CDVPlugin class CDVLogger (pluginName: Console) does not exist.
2014-08-08 18:14:37.229 chatting[7825:70b] ERROR: Plugin 'Console' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.
2014-08-08 18:14:37.229 chatting[7825:70b] -[CDVCommandQueue executePending] [Line 158] FAILED pluginJSON = [
  "INVALID",
  "Console",
  "logLevel",
  [
    "ERROR",
    "Error: 'undefined' is not a function (evaluating 'wnd.focus()')\npopup@http:\/\/auth.mysite.eu\/download\/latest\/oauth.js:323:15\nfacebook@file:\/\/\/Users\/macuser\/Library\/Application%20Support\/iPhone%20Simulator\/7.1\/Applications\/CA5E4763-35DA-44A3-A907-77E58E4CB181\/chatting.app\/www\/assets\/js\/providers.js:27:34\nsignup@file:\/\/\/Users\/macuser\/Library\/Application%20Support\/iPhone%20Simulator\/7.1\/Applications\/CA5E4763-35DA-44A3-A907-77E58E4CB181\/chatting.app\/www\/assets\/js\/controllers.js:91:24\nfile:\/\/\/Users\/macuser\/Library\/Application%20Support\/iPhone%20Simulator\/7.1\/Applications\/CA5E4763-35DA-44A3-A907-77E58E4CB181\/chatting.app\/www\/lib\/ionic\/js\/ionic.bundle.js:19654:26\nfile:\/\/\/Users\/macuser\/Library\/Application%20Support\/iPhone%20Simulator\/7.1\/Applications\/CA5E4763-35DA-44A3-A907-77E58E4CB181\/chatting.app\/www\/lib\/ionic\/js\/ionic.bundle.js:42758:21\n$eval@file:\/\/\/Users\/macuser\/Library\/Application%20Support[...]
Terminating in response to SpringBoard's termination.

最佳答案

我遇到了同样的问题。这个答案让我明白:https://stackoverflow.com/a/20576744/327458 .

在 XCode 中,我必须手动将 CDVInAppBrowser.m 添加到 Build Phases/Compiled Sources。

关于javascript - Cordova/Phonegap oauth.io 弹出窗口未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25176878/

相关文章:

javascript - 在 typescript 中使用react : Progress continues to infinity in timer function

调用 openURL 后 iOS 9.3 卡住

html - IOS8 : whole page scrolls down when input in fixed footer gets focus

android - Phonegap 版本 : accelerometer not working android

javascript - 如何比较两个对象 typescript angular6

javascript - CSS/Javascript 流体字体大小

javascript - 如何从 HTML <td> 组件的内部文本中(仅)删除星号?

ios - 如何从我之前停止的地方播放视频。来自远程服务器 url

jquery - PhoneGap getJSON 调用 REST 服务不起作用

android - Android Gradle Min SDK版本更改导致错误