我在Mac上使用Ionic 2。
Your system information:
Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.4
Ionic CLI Version: 2.1.18
Ionic App Lib Version: 2.1.9
Ionic App Scripts Version: 1.0.0
ios-deploy version: Not installed
ios-sim version: Not installed
OS: macOS Sierra
Node Version: v6.9.4
Xcode version: Xcode 8.2.1 Build version 8C1002
我有一个我一直在开发的应用程序。当我通过Xcode for iOS构建应用程序时,一切正常。
但是当我尝试为Android构建它时,它会生成android-debug.apk
文件,但如果我尝试在模拟器(Android Studio)或我的Android手机上运行它,它似乎加载但随后冻结。
我有3页。它加载初始页面,我可以导航到第二页,但是当我尝试导航到第三页时,导航会冻结。这只发生在Android中。
因此我认为我的第三页可能存在导致导航中断的问题。
如果有人有任何建议,或者可以建议我如何调试,我将非常感谢您的帮助。
这是第三页(不会调用构造函数中的初始警报):
login.ts
import { Component, Inject, forwardRef } from '@angular/core';
import { NavController, AlertController, Platform, Loading, LoadingController } from 'ionic-angular';
import { FirebaseAuth, AuthProviders, FirebaseAuthState } from 'angularfire2';
import { JobModel } from '../model/jobModel';
import { PersonModel } from '../model/personModel';
import { UtilityService } from '../utils/utilityService';
import { PersonService } from '../service/personService';
import { LoginEmailPage } from '../loginemail/loginemail';
import { PersonPage } from '../person/person';
import { PersonUserService } from '../person/personUserService';
@Component({
templateUrl: 'login.html'
})
export class LoginPage {
public jobModel: JobModel;
public personModel: PersonModel;
public fireAuth: firebase.auth.Auth;
public utilityService: UtilityService = null;
public loading: Loading = null;
public authState: FirebaseAuthState = null;
constructor( @Inject(forwardRef(() => UtilityService)) utilityService, public nav: NavController, public auth: FirebaseAuth, public alertCtrl: AlertController, public personService: PersonService, public platform: Platform, public loadingCtrl: LoadingController, public personUserService: PersonUserService) {
alert('login.ts constructor');
this.fireAuth = firebase.auth();
this.utilityService = utilityService;
this.utilityService.logout(this.auth, this.fireAuth);
this.auth.subscribe((authState: FirebaseAuthState) => {
this.authState = authState;
});
}
setUpUser(firebaseAuthState: FirebaseAuthState, provider_id: number): Promise<PersonModel> {
return new Promise<PersonModel>((resolve) => {
let provider: AuthProviders = firebaseAuthState.provider;
if (!provider) {
provider = provider_id;
}
this.personService.getPersonByUidAndProvider(window.localStorage.getItem('uid'), provider).then((personModel: PersonModel) => {
if (personModel && personModel.id) {
this.personModel = personModel;
this.personModel.provider = provider;
if (!this.personModel || !this.personModel.uid) {
this.fireAuth.onAuthStateChanged((user: firebase.User) => {
if (user) {
this.newPerson(user, firebaseAuthState, provider_id).then((data: PersonModel) => {
this.personModel = data;
resolve(this.personModel);
});
}
});
} else {
this.personModel.avatarFirebase = window.localStorage.getItem('photoURL');
this.personModel.lastAccessDate = new Date().getTime();
let user: firebase.User = this.fireAuth.currentUser;
if (!user) {
let loginPromise: Promise<PersonModel> = this.utilityService.login(this.personModel, this.authState.auth, this.nav, this.auth, this.fireAuth, false);
if (loginPromise) {
loginPromise.then((person: PersonModel) => {
resolve(person);
});
} else {
resolve(null);
}
} else {
let loginPromise: Promise<PersonModel> = this.utilityService.login(this.personModel, user, this.nav, this.auth, this.fireAuth, false);
if (loginPromise) {
loginPromise.then((person: PersonModel) => {
resolve(person);
});
} else {
resolve(null);
}
}
}
} else {
let user: firebase.User = this.fireAuth.currentUser;
if (this.authState && this.authState.auth) {
this.newPerson(this.authState.auth, firebaseAuthState, provider_id).then((personData: PersonModel) => {
this.personModel = personData;
resolve(this.personModel);
});
} else if (user) {
this.newPerson(user, firebaseAuthState, provider_id).then((personData: PersonModel) => {
this.personModel = personData;
resolve(this.personModel);
});
} else {
this.doAlert('Logging into Firebase unsuccessful');
console.info('Logging into Firebase unsuccessful', this.authState, user);
}
}
}, (error) => {
console.error('Error getting personModel for uid: ' + window.localStorage.getItem('uid'), error);
});
});
}
newPerson(user: firebase.User, firebaseAuthState: FirebaseAuthState, provider_id: number): Promise<PersonModel> {
return new Promise<PersonModel>(resolve => {
this.personModel = new PersonModel();
if (user && user.email) {
this.personModel.emailAddress = user.email;
} else if (firebaseAuthState && firebaseAuthState.auth && firebaseAuthState.auth.email) {
this.personModel.emailAddress = firebaseAuthState.auth.email;
} else if (this.fireAuth && this.fireAuth.currentUser && this.fireAuth.currentUser.email) {
this.personModel.emailAddress = this.fireAuth.currentUser.email;
} else {
console.error('Firebase current user is null, so cannot get email address and cannot save user to RESTful Service.', this.fireAuth);
}
this.personModel.uid = window.localStorage.getItem('uid');
this.personModel.displayName = window.localStorage.getItem('displayName');
this.personModel.avatarFirebase = window.localStorage.getItem('photoURL');
this.personModel.provider = firebaseAuthState.provider;
this.personModel.lastAccessDate = new Date().getTime();
if (!this.personModel.provider) {
this.personModel.provider = provider_id;
}
if (this.personModel.emailAddress) {
this.utilityService.getPersonLocations(this.personModel).then((person: PersonModel) => {
return this.savePerson(person, user).then((person: PersonModel) => {
resolve(person);
});
}).catch((error) => {
console.info('Saving person, but location not found');
return this.savePerson(this.personModel, user).then((person: PersonModel) => {
resolve(person);
});
});
}
});
}
savePerson(personModel: PersonModel, user: firebase.User): Promise<PersonModel> {
return new Promise<PersonModel>(resolve => {
this.personModel = personModel;
this.personService.savePerson(this.personModel).then((personModel: PersonModel) => {
this.utilityService.login(personModel, user, this.nav, this.auth, this.fireAuth, true).then((person: PersonModel) => {
resolve(person);
});
});
});
}
signIn(firebaseAuthState: FirebaseAuthState, provider_id: number) {
let emailVerified: boolean = false;
let user: firebase.User = this.fireAuth.currentUser;
if (user) {
if (user.emailVerified) {
emailVerified = true;
}
} else {
if (firebaseAuthState.auth && firebaseAuthState.auth.emailVerified) {
emailVerified = true;
}
}
if (firebaseAuthState && firebaseAuthState.uid) {
this.setUpUser(firebaseAuthState, provider_id).then((personModel: PersonModel) => {
if (personModel && emailVerified) {
this.nav.setRoot(PersonPage, {
personModel: personModel,
fromLogin: true
}).then(() => {
this.loading.dismiss();
});
}
});
}
window.setTimeout(() => {
this.loading.dismiss();
}, 6000);
}
// sanityCheck(firebaseAuthState: FirebaseAuthState): void {
// if (firebaseAuthState && firebaseAuthState.auth && !firebaseAuthState.auth.emailVerified) {
// this.personService.getPersonByUid(firebaseAuthState.uid).then((personModel: any) => {
// if (!personModel) {
// console.error('RDS PersonModel does not exist for Firebase User ', personModel, firebaseAuthState);
// firebaseAuthState.auth.delete().then(() => {
// console.info('Firebase User deleted', firebaseAuthState);
// });
// } else if (personModel.ok === false) {
// console.error('RDS PersonModel does not exist for Firebase User ', personModel, firebaseAuthState);
// firebaseAuthState.auth.delete().then(() => {
// console.info('Firebase User deleted', firebaseAuthState);
// });
// }
// }).catch((error) => {
// console.error('RDS PersonModel does not exist for Firebase User ', firebaseAuthState);
// firebaseAuthState.auth.delete().then(() => {
// console.info('Firebase User deleted', firebaseAuthState);
// });
// });
// }
// }
loginGoogle(): void {
this.loading = this.loadingCtrl.create({
content: 'Please wait...'
});
this.loading.present();
this.personUserService.init(this.nav, this.personModel, null, this.loading);
if (this.platform.is('cordova')) {
this.platform.ready().then(() => {
this.personUserService.loginGoogleCordova().then((data: FirebaseAuthState) => {
this.signIn(data, AuthProviders.Google);
});
});
} else {
this.personUserService.loginGoogleBrowser().then((data: FirebaseAuthState) => {
this.signIn(data, AuthProviders.Google);
});
}
}
loginFacebook(): void {
alert('login.ts loginFacebook');
this.loading = this.loadingCtrl.create({
content: 'Please wait...'
});
// this.loading.present();
this.personUserService.init(this.nav, this.personModel, null, this.loading);
alert('login.ts loginFacebook just initialised personUserService');
if (this.platform.is('cordova')) {
alert('login.ts loginFacebook cordova');
this.platform.ready().then(() => {
alert('login.ts loginFacebook ready');
this.personUserService.loginFacebookCordova().then((data: FirebaseAuthState) => {
alert('login.ts loginFacebook loginFacebookCordova done');
this.signIn(data, AuthProviders.Facebook);
});
});
} else {
alert('login.ts loginFacebook not cordova');
this.personUserService.loginFacebookBrowser().then((data: FirebaseAuthState) => {
alert('login.ts loginFacebook loginFacebookBrowser done');
this.signIn(data, AuthProviders.Facebook);
});
}
}
loginEmail() {
this.nav.push(LoginEmailPage);
}
doAlert(msg: string) {
let alert = this.alertCtrl.create({
title: 'Login',
subTitle: msg,
buttons: ['Dismiss']
});
alert.present();
}
}
更新
找到导致它崩溃的原因,但我不知道为什么。
在构造函数中:
alert('personUserService.ts constructor');
alert('personUserService.ts constructor firebase = '+firebase);
this.fireAuth = firebase.auth();
alert('personUserService.ts constructor this.fireAuth = '+this.fireAuth);
this.auth.subscribe((authState: FirebaseAuthState) => {
this.authState = authState;
});
调用第一个警报,然后冻结。这意味着firebase
对象导致它冻结。
这适用于iOS
,所以不确定为什么它不在Android
。
firebase
是引用firebase.d.ts
文件夹中node_modules/firebase/server-auth-node/
的命名空间。
答案 0 :(得分:0)
我做了以下事情,我的所有问题都消失了:
1)ionic platform rm android
2)ionic platform add android