2019年12月5日 星期四

[morse]Using WifiWizard2 with Ionic

安裝WifiWizrd2插件
ionic cordova plugin add wifiwizard2



 home.page.html
< ion-header>
  < ion-toolbar>
    < ion-title>
     List Wifi AP
    < /ion-title>
  < /ion-toolbar>
< /ion-header>

< ion-content padding>

    < ion-button color="primary" (click)="getNetworks()">Get Networks< /ion-button>
    {{info_txt}}
    < ion-list>
        < ion-item *ngFor="let data of results">
            {{data.SSID}} -
            {{data.BSSID}}
        < /ion-item>
      < /ion-list>
< /ion-content>


 home.page.ts
import { Component } from '@angular/core';

declare var WifiWizard2: any;

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage {
  results = [];
  info_txt = "";
  async getNetworks() {
    this.info_txt = "loading...";
    try {
      let results = await WifiWizard2.scan();
      this.results = results;
      this.info_txt = "";
    } catch (error) {
      this.info_txt = error;
    }
  }
}


注意: 需在模擬器或手機上才能試出效果。



沒有留言:

張貼留言