ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • and_181207
    Android 2018. 12. 7. 21:55


    리얼타임 데이터베이스로 변경

    더미용 데이터를 변수이름에 맞게 제작한다


    규칙을 변경한다 

    규칙을 변경

    initPage(){
    var userRef = firebase.database().ref('users/');
    userRef.on('value',(items :any)=>{
    this.users = [];
    if(items.val()){
    items.forEach(item => {
    this.users.push({
    name : item.val().name,
    email : item.val().email,
    password : item.val().password,
    date : item.val().date,
    id: item.val().id
    })
    console.log(item.val().name);
    });
    }else{
    console.log('사용자 목록 조회 실패 ');
    }
    });

    한번 목록조회 실패가 뜸 

    var userRef = firebase.database().ref('users/');에서

    users와

    파이어베이스의 프로젝트 바로아래의 이름이 같아야한다


    import { Component } from '@angular/core';
    import { IonicPage, NavController, NavParams } from 'ionic-angular';
    import * as firebase from "firebase";
    /**
    * Generated class for the SignupPage page.
    *
    * See https://ionicframework.com/docs/components/#navigation for more info on
    * Ionic pages and navigation.
    */

    @IonicPage()
    @Component({
    selector: 'page-signup',
    templateUrl: 'signup.html',
    })
    export class SignupPage {
    private account : any ={
    name : '',
    email : '',
    password : '',
    date:'',
    id : ''
    };
    constructor(public navCtrl: NavController, public navParams: NavParams) {
    }

    ionViewDidLoad() {
    console.log('ionViewDidLoad SignupPage');
    }
    //firebase database 에 추가하는 방법
    async signup (){
    try{
    const result = await firebase.auth()
    .createUserWithEmailAndPassword(this.account.email, this.account.password);
    if(result){
    console.log(result);
    var tmpUser = {
    name : this.account.name,
    email : this.account.email,
    password : this.account.password,
    date : this.account.date,
    id: result.uid
    };

    }
    }catch{

    }
    }

    //firebas Auth...에 추가하는 방법
    // signup(){
    // firebase.auth()
    // .createUserWithEmailAndPassword(this.account.email, this.account.password)
    // .then((result)=>{
    // console.log(result);
    // var user = firebase.auth().currentUser;
    // var user = firebase.auth().currentUser;

    // user.updateProfile({
    // displayName: "Jane Q. User",
    // photoURL: "https://example.com/jane-q-user/profile.jpg"
    // }).then(()=> {
    // // Update successful.
    // console.log('회원가입성공')
    // }).catch((error)=> {
    // // An error happened.
    // console.log(error.message);
    // });
    // })//프로미스 패턴
    // .catch((error)=> {
    // // Handle Errors here.
    // console.log(error.message);
    // var errorCode = error.code;
    // var errorMessage = error.message;
    // // ...
    // });
    // }
    }

    https://momentjs.com/


    npm install moment --save
    import * as moment from 'moment';


    import { Component } from '@angular/core';
    import { IonicPage, NavController, NavParams } from 'ionic-angular';
    import * as firebase from "firebase";
    import * as moment from 'moment';
    /**
    * Generated class for the SignupPage page.
    *
    * See https://ionicframework.com/docs/components/#navigation for more info on
    * Ionic pages and navigation.
    */

    @IonicPage()
    @Component({
    selector: 'page-signup',
    templateUrl: 'signup.html',
    })
    export class SignupPage {
    private account : any ={
    name : '',
    email : '',
    password : ''
    };
    constructor(public navCtrl: NavController, public navParams: NavParams) {
    }

    ionViewDidLoad() {
    console.log('ionViewDidLoad SignupPage');
    }
    //firebase database 에 추가하는 방법
    async signup (){
    try{
    const result = await firebase.auth()
    .createUserWithEmailAndPassword(this.account.email, this.account.password);
    if(result){
    console.log(result);
    var tmpUser = {
    name : this.account.name,
    email : this.account.email,
    password : this.account.password,
    date : moment().format('YYYY-MM-DD'),
    id: result.uid
    };
    var updates = {};
    updates['/users/'+result.uid]=tmpUser;
    firebase.database().ref().update(updates);
    }
    }catch(error){
    console.log('회원추가 실패');
    }
    }

    //firebas Auth...에 추가하는 방법
    // signup(){
    // firebase.auth()
    // .createUserWithEmailAndPassword(this.account.email, this.account.password)
    // .then((result)=>{
    // console.log(result);
    // var user = firebase.auth().currentUser;
    // var user = firebase.auth().currentUser;

    // user.updateProfile({
    // displayName: "Jane Q. User",
    // photoURL: "https://example.com/jane-q-user/profile.jpg"
    // }).then(()=> {
    // // Update successful.
    // console.log('회원가입성공')
    // }).catch((error)=> {
    // // An error happened.
    // console.log(error.message);
    // });
    // })//프로미스 패턴
    // .catch((error)=> {
    // // Handle Errors here.
    // console.log(error.message);
    // var errorCode = error.code;
    // var errorMessage = error.message;
    // // ...
    // });
    // }
    }

    auth에 등록하고


    export class HomePage {
    private userName : any; //자바의 제네릭 같은 개념
    private userEmail : any;
    private userId : any ;
    private userProfile ={
    name : '',
    email:'',
    password:'',
    date: '',
    id: ''

    } 


    home.ts

    import { Component } from '@angular/core';
    import { NavController, AlertController } from 'ionic-angular';
    import * as firebase from "firebase";
    import { ManagerPage } from '../manager/manager';
    import { async } from '@firebase/util';
    @Component({
    selector: 'page-home',
    templateUrl: 'home.html'
    })
    export class HomePage {
    private userName : any; //자바의 제네릭 같은 개념
    private userEmail : any;
    private userId : any ;
    private userDate : any ;
    private userProfile ={
    name : '',
    email:'',
    password:'',
    date: '',
    id: ''
    }

    constructor(public navCtrl: NavController,
    private alertCtrl : AlertController) {
    //this.initPage();
    this.getUserProfile();
    }
    async getUserProfile(){//database에서 가져오는 정보
    try{
    const userId = await firebase.auth().currentUser.uid;
    if(userId){
    var userRef = firebase.database().ref("users/"+userId);
    userRef.once('value',(item:any)=>{
    if(item.val()){
    this.userProfile={
    name : item.val().name,
    email : item.val().email,
    password : item.val().password,
    date : item.val().date,
    id: item.val().id
    }
    }else{console.log("데이터가 없음");}
    }).then(()=>{
    console.log('사용자 정보 제공');
    // this.initPage();
    this.userName = this.userProfile.name;
    this.userEmail = this.userProfile.email;
    this.userId =this. userProfile.id;
    this.userDate =this. userProfile.date;
    });
    }
    }catch{

    }

    }
    initPage(){//auth 에서 가져오는 정보처리
    var user = firebase.auth().currentUser;
    console.log(user);
    if(user){
    this.userName = user.displayName;
    this.userEmail = user.email;
    this.userId = user.uid;
    }else{
    console.log('로그인된 사용자가 없습니다.');
    }
    }
    logout(){
    let confirm = this.alertCtrl.create({
    title : '로그아웃',
    message : '로그아웃 하시겠습니까?',
    buttons:[{
    text : '아니요',
    handler : ()=>{
    console.log('로그아웃 취소');
    }
    },{
    text : '예',
    handler : ()=>{
    console.log("로그아웃 확인");
    firebase.auth().signOut()
    .then(()=>{
    console.log('로그아웃 실행');
    })
    .catch(error=>{console.log(error);});
    }

    }]
    });//this로 정의된것은 constructer에 추가해야한다.
    confirm.present();
    }
    //매니저 페이지로 전환
    gotoManagerPage(){
    this.navCtrl.push(ManagerPage);
    }
    }


    아이오닉 기반 앱 APK 앱올리기 

    config. xml 

    <widget id="kr.tmxhsk99itbank.app" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>MyApp</name>
    <description>An awesome Ionic/Cordova app.</description>
    <author email="tmxhsk99@naver.com" href="http://ionicframework.com/">Ionic Framework Team</author>



    https://ionicframework.com/docs/intro/deploying/


    Sign Android APK

    If you want to release your app in the Google Play Store, you have to sign your APK file. To do this, you have to create a new certificate/keystore.

    Let’s generate your private key using the keytool command that comes with the JDK:

    keytool -genkey -v -keystore my-release-key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias my-alias

    cmd에서 keytool 처서 확인 

    ionic 프로젝트 폴더 안에서 cmd 킨다 

    https://medium.com/@changjoopark/%EC%95%84%EC%9D%B4%EC%98%A4%EB%8B%89%ED%94%84%EB%A0%88%EC%9E%84%EC%9B%8C%ED%81%AC-3-%EA%B8%B0%EB%B3%B8-%EC%95%B1-%EB%B9%8C%EB%93%9C-%EC%8B%A4%ED%8C%A8%EC%8B%9C-%EC%B6%94%EA%B0%80-%EC%84%A4%EC%A0%95%ED%95%98%EA%B8%B0-e8e707e1c11a

    npm update 

    안드로이드 스튜디오 import project 

    ionic에서 플랫폼 폴더 에서 android를 import

    No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android

    http://crmn.tistory.com/75



    사물인터넷 쪽과

    화려한 하이브리드앱

    'Android' 카테고리의 다른 글

    and_181210  (0) 2018.12.10
    and_181204  (0) 2018.12.04
    And_181203 아이오닉+앵귤러JS 세팅  (0) 2018.12.03
    and_181130  (0) 2018.11.30
    And_181128  (0) 2018.11.28
Designed by Tistory.