我在 iOS 设备上的 cordova-plugin-facebook4 (https://github.com/jeduan/cordova-plugin-facebook4)出现问题。按照文档(“ iOS指南”)中所述的安装步骤并在Facebook开发者控制台中正确配置了应用程序之后, 当我单击我的Facebook登录按钮时,没有任何反应。 XCODE控制台输出以下错误:
2019-02-15 17:22:58.678937+0100 HelloCordovaApp[59179:1228209] Logging in with CORDOVA ... 2019-02-15 17:22:58.692742+0100 HelloCordovaApp[59179:1228209] Checking login status: unknown 2019-02-15 17:22:58.692947+0100 HelloCordovaApp[59179:1228209] Performing Fb login ... 2019-02-15 17:22:58.693087+0100 HelloCordovaApp[59179:1228209] Starting login 2019-02-15 17:22:58.693271+0100 HelloCordovaApp[59179:1228209] *** WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: <NSInvalidArgumentException> Permissions should each be specified in separate string values in the array. 2019-02-15 17:22:58.694627+0100 HelloCordovaApp[59179:1228209] Client application failed to make a policy decision via WebPolicyDecisionListener, using defaultPolicy 2
我开发的应用程序是用AngularJs编写的,并使用Cordova包装。 会是什么呢?在 Android 设备上,它可以完美运行... 这是用户单击我的Facebook登录按钮时执行的代码:
function fbLoginButtonClick(){
console.log('Logging in with CORDOVA ...');
facebookConnectPlugin.getLoginStatus(_fbLoginStatusSuccess, _fbLoginStatusError);
}
////////
function _fbLoginStatusSuccess(response) {
var responseStatus = response.status;
console.log('Checking login status: ', responseStatus);
if (responseStatus === 'connected') {
_fbLoginSuccess();
} else if (responseStatus !== null) {
_doFbLogin();
} else {
handleFacebookError(responseStatus);
}
}
function _fbLoginStatusError(error) {
handleFacebookError(error);
}
function _doFbLogin() {
console.log('Performing Fb login ...');
facebookConnectPlugin.login(['email, public_profile'], _fbLoginSuccess, _fbLoginError);
}
function _fbLoginSuccess(result) {
console.log('Fb API: getting user data ...');
facebookConnectPlugin.api('/me?fields=id,name,first_name,last_name,email', ['email', 'public_profile'], _fbApiSuccess, _fbApiError);
}
function _fbLoginError(error) {
handleFacebookError(error);
}
function _fbApiSuccess(userData) {
alert('User Authenticated!!');
//redirect to admin page
}
function _fbApiError(error) {
handleFacebookError(error);
}
function handleFacebookError (error) {
if(error){
console.log(error);
}
}
这是我的config.xml文件中的配置:
<plugin name="cordova-plugin-facebook4" spec="4.2.1">
<variable name="APP_ID" value="************" />
<variable name="APP_NAME" value="HelloCordovaApp" />
<variable name="FACEBOOK_HYBRID_APP_EVENTS" value="false" />
<variable name="FACEBOOK_ANDROID_SDK_VERSION" value="4.40.0" />
</plugin>
答案 0 :(得分:0)
我花了一些时间才弄清楚这一点,基本上错误是您传递给SDK的权限的类型错误。解决方法如下:
替换此行:
facebookConnectPlugin.login(['email, public_profile'], _fbLoginSuccess, _fbLoginError);
使用:
var perms = new Array("email","public_profile");
facebookConnectPlugin.login(perms, _fbLoginSuccess, _fbLoginError);
这应该为您解决问题。祝你好运!