我正在使用Mac上的离子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
我有一个正在开发的应用程序。当我通过iOS XCode构建应用程序时,一切正常。
但是,当我尝试为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();
}
}
update
找到导致它崩溃的原因,但我不知道为什么。
构造函数:
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
是node_modules/firebase/server-auth-node/
文件夹中引用firebase.d.ts
的名称空间。
我做了以下操作,我所有的问题都消失了:
1)ionic platform rm android
2)ionic platform add android