首页 > 解决方案 > Facebook 登录按钮需要点击两次才能在 Safari / iPhone 中工作,为什么?

问题描述

我在我的网站中使用默认的 Facebook 登录按钮。它适用于所有桌面浏览器,它也适用于我的带有 Firefox 和 Chrome 的 iPhone。但是,当我使用 Safari 时,我必须在按钮上单击两次才能发送请求。

我听说 Safari 普遍存在这个问题。有人对此有解决方案吗?

这是我使用的代码:

              function getInfos() {
                FB.api('/me', {fields: 'first_name,last_name,email,id'}, function(response) {
                  var fn = ('first_name' in response) ? response.first_name : "null";
                  var ln = ('last_name' in response) ? response.last_name : "null";
                  var fid = ('id' in response) ? response.id : "null";
                  var mail = ('email' in response) ? response.email : "null";
                  // ... SUCCESS!! and whatever you want to do with the FB data...
                });
              }

              function processLoginStatus(response) {
                if (response.status === 'connected') {
                  getInfos();
                } else {
                  FB.login(function(response) {
                    if (response.authResponse) {
                      processLogin(response);
                    } else {
                      // user clicked cancel
                    }
                  }, {scope: 'public_profile,email'});
                }
              }
            
              function processLogin(response) {
                if (response.status === 'connected') {
                  getInfos();
                } else if (response.status === 'not_authorized') {
                  console.log("processLogin: not authorized");
                } else {
                  console.log("processLogin: else");
                }
              }
            
              function checkLoginState() {
                FB.getLoginStatus(function(response) {
                  processLoginStatus(response);
                });
              }

              $(document).ready(function() {
                if ($('.facebooklogin').length != 0) {
                  if (typeof FB === 'undefined' || FB === null) {
                  } else {
                    FB.init({
                      appId      : 'MYAPPID',
                      cookie     : true,
                      xfbml      : true,
                      version    : 'v7.0'
                    });
                    $('button.facebooklogin').click(function() {
                      checkLoginState();
                    });
                  }
                }
              });

标签: iphonemacosfacebooksafari

解决方案


推荐阅读