Cordova / Phonegap oauth.io popup没有显示

时间:2014-08-07 07:44:49

标签: javascript ios cordova oauth

我正在开发一个cordova webapp,实际上我集成了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.

1 个答案:

答案 0 :(得分:2)

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

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