【问题标题】:Ionic 3 Firebase Google Auth stoped working in Android deviceIonic 3 Firebase Google Auth 在 Android 设备中停止工作
【发布时间】:2018-11-26 16:18:19
【问题描述】:

在我尝试实现通知之前,我的应用程序运行良好,在 android 设备上运行时出现 firebase 拒绝连接和 404 错误,但在浏览器上一切正常。然后重新安装了每个插件和模块,解决了firebase连接的问题,但谷歌原生登录方法根本不起作用,甚至没有抛出任何错误

signInWithGoogle() { 
    if (this.platform.is('cordova')) {
        this.nativeGoogleLogin();
    }else{
        this.webGoogleLogin().then(()=>{});
    }
}
async nativeGoogleLogin(): Promise<void>{
    try {
        this.loading.present();
        const gplusUser = await this.gplus.login({
            'webClientId':'******',
            'offline':true,
            'scopes':'profile email'
        }) 
        console.log('NativeLogin');
        return await this.afAuth.auth.signInWithCredential(
            firebase.auth.GoogleAuthProvider.credential(gplusUser.idToken))

        // return await this.afAuth.auth.signInAndRetrieveDataWithCredential(
        //     firebase.auth.GoogleAuthProvider.credential(gplusUser.idToken))
        .then(data =>{
            this.loading.dismiss();
            console.log(data);
            this.updateUserData(data.user);
        }).catch(err =>{
            this.loading.dismiss();
            console.log('NativeLoginError',err);
        })
    } catch (error) {
        this.loading.dismiss();
        console.error('NativeLoginError',error); 
    }
}

异步方法甚至不是控制台记录文本。

console.log('NativeLogin');

我仔细检查了 webClientId。正在努力解决这个问题

【问题讨论】:

  • 你的 cordova android 版本是多少?
  • @fahadsk Cordova android 7.1.0 出现 androidManifist.xml 错误,因此降级为 cordova-android: 6.4.0
  • 你检查过降级到 6.3.0 吗?
  • 是的,刚刚检查过,降级到 6.3.0 后它没有立即工作,在我删除 native-firebase 插件后它工作。我想知道问题是否是由于 native-firebase 插件本身。感谢您的帮助

标签: android firebase ionic3 angularfire2 ionic-native


【解决方案1】:

所以您在安装 Firebase 通知时开始看到错误?流式细胞仪?我会先卸载它,然后看看问题是否仍然存在。有时插件具有相互冲突的依赖关系,并且相互混淆。

您是否在应用程序运行时安装了 FCM?根据我的经验,它会弄乱热重载,并且它不再知道东西应该正确定位在哪里,所以如果是这样的话,一个简单的停止和启动应该可以解决这个问题。

尝试运行 ionic doctor check 这将解决 ionic 项目在 CLI 方面遇到的任何问题。

另外,稍微清理一下您的代码,使其更易于理解。

signInWithGoogle() { 
    if (this.platform.is('cordova')) {
        this.nativeGoogleLogin().then(data => {
    this.loading.dismiss();
    this.updateUserData(data.user);
}).catch(err => { console.log('Native login error: ', JSON.stringify(err); });
    } else {
        this.webGoogleLogin();
    }
}

nativeGoogleLogin(): Promise<void> { // Personally I would take this out of the try catch because you already are catching the error with the .catch of your promise.

this.loading.present();
const gplusUser = await this.gplus.login({
            'webClientId':'******',
            'offline':true,
            'scopes':'profile email'
        });
return await this.afAuth.auth.signInWithCredential(
            firebase.auth.GoogleAuthProvider.credential(gplusUser.idToken));
}

要检查的另一件事是查看您是否真的调用了 signInWithGoogle() 方法,因为这是我刚开始时经常犯的一个错误。

也可以尝试在任何地方输入console.log消息,我个人最喜欢做的事情是以下,尤其是在开发时。

console.log('File-name.ts: What-Im-Attempting-to-do: status(error, success or JSON.stringify(data);');

这样可以更轻松地跟踪错误,而不必记住每个错误应该与什么分开。

如果所有这些都不起作用,请尝试完全删除您的平台,然后重新添加它。

ionic cordova platform rm ios/android 
ionic cordova platform add ios/android

希望这会有所帮助!

【讨论】:

  • 1) 我已恢复原状,卸载了我为通知而安装的所有插件,2) 我进行了医生检查,并通过一些插件更新修复了 1 个问题,但并没有解决问题。 3) 检查 signInWithGoogle() 方法正在运行,并且在 nativeGoogleLogin() 内部我保持 TryCatch,在 tryCatch 外部运行,但内部没有。 4)我删除了平台和插件并重新安装了多次,但它没有工作。我什至创建了一个全新的项目,将 src 和 package.json 复制到新项目中并运行它,甚至新应用程序也无法正常工作。 :( :(
  • 感谢帮助,看来是cordova-android版本的问题,降级到6.3.0,还有native-firebase插件的问题。
猜你喜欢
  • 2014-04-09
  • 1970-01-01
  • 1970-01-01
  • 2021-07-15
  • 2017-09-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多