顯示具有 Ionic 標籤的文章。 顯示所有文章
顯示具有 Ionic 標籤的文章。 顯示所有文章

2021年9月29日 星期三

[Q&A] Send image from ionic to asp.net core (IFormFile) web api

 [Q]

We are looking to upload image from ionic to .net core web api. To achieve this we are using file transfer plugin.

So, far we understood that image will be converted into base64. However, what we are looking is how can we sent form data along with multiple image to web api?

Below is the code from ionic side.

HTML code to trigger select image function:

<ion-button fill="clear" expand="full" color="light" (click)="selectImage()">
      <ion-icon slot="start" name="camera"></ion-icon>
      Select Image</ion-button>

Component file code to upload image using ionic camera Plugin:

async selectImage() {
      const actionSheet = await this.actionSheetController.create({
          header: "Select Image source",
          buttons: [{
                  text: 'Load from Library',
                  handler: () => {
                      this.takePicture(this.camera.PictureSourceType.PHOTOLIBRARY);
                  }
              },
              {
                  text: 'Use Camera',
                  handler: () => {
                      this.takePicture(this.camera.PictureSourceType.CAMERA);
                  }
              },
              {
                  text: 'Cancel',
                  role: 'cancel'
              }
          ]
      });
      await actionSheet.present();
  }

  takePicture(sourceType: PictureSourceType) {
      var options: CameraOptions = {
          quality: 100,
          sourceType: sourceType,
          saveToPhotoAlbum: false,
          correctOrientation: true
      };

      this.camera.getPicture(options).then(imagePath => {
        this.base64img="data:image/jpeg;base64,"+imagePath;
        this.uploadPic();
      });

  }

Component file code to pass image to web api:

uploadPic() {
        const fileTransfer: FileTransferObject = this.transfer.create();
        let filename = this.base64img.split('/').pop();
        let options: FileUploadOptions = {
            fileKey: "file",
            fileName: filename,
            chunkedMode: false,
            mimeType: "image/jpg",
            params: { 'title': this.imageTitle }
        }

        fileTransfer.upload(this.base64img, '<api endpoint>', options).then(data => {
          alert(JSON.stringify(data));
        }, error => {

          alert("error");
          alert("error" + JSON.stringify(error));
        });
      }

By doing this we are able to get the file in HttpContext.Request.Form.Files, but how can we get this in [FromBody] request parameter in web api? So, that I can get form data as well images to upload.

Also, we have tried by adding only one request parameter in web api, by assuming that the base64 which passed from client side will be received at in request parameter. But this also didn't work, which has given error 'Value cannot be null'.




[A]


You can send base64 data to any server API using HttpClientModule

Just do following changes in your code

Step 1: In app.module.ts

import { HttpClientModule } from '@angular/common/http';

include HttpClientModule in imports

Step 2: In page.ts

import { HttpClient } from '@angular/common/http';

constructor(private httpClient: HttpClient) { }

Initialise HttpClient in the constructor of page.ts

 sendData(base64img,other_data) {
    let _url = "";
    let formData = new FormData();
    formData.append("base64img", base64img);
    formData.append("other_data", other_data);
    this.httpClient.post(_url, formData).subscribe((res) => {
    //res contains server response
    });
  }





from:
https://stackoverflow.com/questions/58429122/send-image-from-ionic-to-asp-net-core-web-api

2021年4月9日 星期五

Ionic error message: Unsupported engine package: '@angular/cli@11.1.4'

Error message:
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@angular/cli@11.1.4',
npm WARN EBADENGINE   required: { node: '>= 10.13.0', npm: '^6.11.0', yarn: '>= 1.13.0' },
npm WARN EBADENGINE   current: { node: 'v12.5.0', npm: '7.8.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@angular-devkit/architect@0.1101.4',
npm WARN EBADENGINE   required: { node: '>= 10.13.0', npm: '^6.11.0', yarn: '>= 1.13.0' },
npm WARN EBADENGINE   current: { node: 'v12.5.0', npm: '7.8.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@angular-devkit/core@11.1.4',
npm WARN EBADENGINE   required: { node: '>= 10.13.0', npm: '^6.11.0', yarn: '>= 1.13.0' },
npm WARN EBADENGINE   current: { node: 'v12.5.0', npm: '7.8.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@angular-devkit/schematics@11.1.4',
npm WARN EBADENGINE   required: { node: '>= 10.13.0', npm: '^6.11.0', yarn: '>= 1.13.0' },
npm WARN EBADENGINE   current: { node: 'v12.5.0', npm: '7.8.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@schematics/angular@11.1.4',
npm WARN EBADENGINE   required: { node: '>= 10.13.0', npm: '^6.11.0', yarn: '>= 1.13.0' },
npm WARN EBADENGINE   current: { node: 'v12.5.0', npm: '7.8.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@angular-devkit/core@11.1.4',
npm WARN EBADENGINE   required: { node: '>= 10.13.0', npm: '^6.11.0', yarn: '>= 1.13.0' },
npm WARN EBADENGINE   current: { node: 'v12.5.0', npm: '7.8.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@angular-devkit/schematics@11.1.4',
npm WARN EBADENGINE   required: { node: '>= 10.13.0', npm: '^6.11.0', yarn: '>= 1.13.0' },
npm WARN EBADENGINE   current: { node: 'v12.5.0', npm: '7.8.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@schematics/update@0.1101.4',
npm WARN EBADENGINE   required: { node: '>= 10.13.0', npm: '^6.11.0', yarn: '>= 1.13.0' },
npm WARN EBADENGINE   current: { node: 'v12.5.0', npm: '7.8.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@angular-devkit/core@11.1.4',
npm WARN EBADENGINE   required: { node: '>= 10.13.0', npm: '^6.11.0', yarn: '>= 1.13.0' },
npm WARN EBADENGINE   current: { node: 'v12.5.0', npm: '7.8.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@angular-devkit/schematics@11.1.4',
npm WARN EBADENGINE   required: { node: '>= 10.13.0', npm: '^6.11.0', yarn: '>= 1.13.0' },
npm WARN EBADENGINE   current: { node: 'v12.5.0', npm: '7.8.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@stencil/core@2.5.2',
npm WARN EBADENGINE   required: { node: '>=12.10.0', npm: '>=6.0.0' },
npm WARN EBADENGINE   current: { node: 'v12.5.0', npm: '7.8.0' }
npm WARN EBADENGINE }  



Solution:
$ npm -v
7.5.0

$ npm install --global npm@6

removed 60 packages, changed 194 packages, and audited 436 packages in 30s

3 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

$ npm -v
6.14.11

$ npm install -g @angular/cli
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this library is no longer supported
/usr/local/bin/ng -> /usr/local/lib/node_modules/@angular/cli/bin/ng

> @angular/cli@11.1.4 postinstall /usr/local/lib/node_modules/@angular/cli
> node ./bin/postinstall/script.js

? Would you like to share anonymous usage data with the Angular Team at Google u
nder
Google’s Privacy Policy at https://policies.google.com/privacy? For more details
 and
how to change this setting, see http://angular.io/analytics. Yes

Thank you for sharing anonymous usage data. If you change your mind, the following
command will disable this feature entirely:

    ng analytics off

+ @angular/cli@11.1.4
added 5 packages from 2 contributors, removed 7 packages and updated 234 packages in 103.594s
————————————————
  

 

2021年3月24日 星期三

關於 RxJS 裡的 BehaviorSubject 可以怎麼用!

 RxJS 裡的 Subject 有 4 種類型,Subject、BehaviorSubject、ReplaySubject 和 AsyncSubject,每一種類型的 Subject 都有各自的特性及使用時機,這次會使用 BehaviorSubject來管理使用者的登入狀態


BehaviorSubject

BehaviorSubject 與一般的 Subject 有什麼不一樣,差別有兩個

  1. BehaviorSubject 可以給予初始值
  2. 每一個 Observer 都可以在註冊的當下,立刻取得目前 BehavoirSubject 的值 (以下皆簡稱為 Subject)

這兩種特性,就非常適合用在使用者登入狀態管理的這種情境

使用情境

使用者登入基本上,狀態就兩種,登入與尚未登入,而每一個頁面都可以在取得該使用者目前的登入狀態。也可以即時知道已登入的使用者登出的時間點。

根據上列的描述,我們會實作一個 UserService,用來執行跟管理使用者的登入,登出行為及狀態。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from "rxjs";

@Injectable()
export class UserService {
isLoginSubject = new BehaviorSubject<boolean>(this.hasToken());

/**
* 如果有取得token,表示使用者有登入系統
* @returns {boolean}
*/
private hasToken() : boolean {
return !!localStorage.getItem('token');
}

/**
* 登入使用者,並通知所有訂閱者
*/
login() : void {
localStorage.setItem('token', 'JWT');
this.isLoginSubject.next(true);
}

/**
* 登出使用者,並通知所有訂閱者
*/
logout() : void {
localStorage.removeItem('token');
this.isLoginSubject.next(false);
}

/**
*
* @returns {Observable<T>}
*/
isLoggedIn() : Observable<boolean> {
return this.isLoginSubject.asObservable();
}
}

Component 的使用方式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { Component, OnInit } from '@angular/core';
import { AuthService } from "../auth.service";
import { Observable } from "rxjs";

@Component({
selector: 'app-main-nav',
template: `
<ul>
<li *ngIf="!(isLoggedIn | async)" (click)="authService.login()>
<a>Login</a>
</li>
<li *ngIf="(isLoggedIn | async)" (click)="authService.logout()">
<a>Logout</a>
</li>
</ul>
`
})
export class MainNavComponent implements OnInit {
isLoggedIn : Observable<boolean>;

constructor( public userService : UserService ) {
this.isLoggedIn = userService.isLoggedIn();
}
}

這樣子就完成了一個陽春型的使用者登入狀態管理 service。



參考資料

2021年3月21日 星期日

No pipe found with name 'translate'

 Error message:

error NG8004: No pipe found with name 'translate'.



page module 要作如下配置:

import { TranslateModule } from '@ngx-translate/core';


@NgModule({

  imports: [

TranslateModule

  ],

  exports: [

TranslateModule

  ]

})


If 'ion-title' is an Angular component, then verify that it is part of this module.

 Error message:

1. If 'ion-title' is an Angular component, then verify that it is part of this module.

2. If 'ion-title' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.


page ts 要加 entryComponents:

const tmpModule = NgModule({

         declarations: [tmpCmp],

         imports:[IonicModule],

         entryComponents: [tmpCmp]

    })(class {});


2021年3月20日 星期六

ionic buile error: No provider for LocalNotifications

Error message:

core.js:6140 ERROR NullInjectorError: R3InjectorError(AppModule)[cls_localnotifications -> LocalNotifications -> LocalNotifications -> LocalNotifications]: 

  NullInjectorError: No provider for LocalNotifications!


Soluction:

app.module.ts  add:

import { LocalNotifications } from '@ionic-native/local-notifications/ngx';

providers: [

    LocalNotifications,

]


         

2021年3月16日 星期二

No targets devices/emulators available. 使用模擬器出現異常,無法使用

指令:ionic cordova emulate android 

異常訊息:

[native-run] ERR_NO_TARGET: No targets devices/emulators available. Cannot create AVD because there is no suitable API installation. Use --sdk-info to reveal missing packages and other issues.


avdmanager list avd    --列出所有系統中所有的AVD    

(環境變數中要有 %ANDROID_HOME%\tools\bin 才可以執行)


avdmanager list target --列出目標的AVD


C:\Users\morse>avdmanager list target

Available Android targets:==============] 100% Fetch remote repository...

----------

id: 1 or "android-19"

Name: Android API 19

Type: Platform

API level: 19

Revision: 4

----------

id: 2 or "android-28"

Name: Android API 28

Type: Platform

API level: 28

Revision: 6

----------

id: 3 or "android-29"

Name: Android API 29

Type: Platform

API level: 29

Revision: 4

ionic指定模擬器:

手機

ionic cordova emulate android --target=Nexus_5X_API_26_x86

ionic cordova emulate android --target=Nexus_5X_API_26_x86 --verbose

ionic cordova emulate android --target=Nexus_5X_API_26_x86 --warning-mode all

平板

ionic cordova emulate android --target=Nexus_9_API_27


SDK 管理工具

sdkmanager --install "system-images;android-29;default;x86"


ionic admob enabling test ads

 在開發過程中啟用測試廣告很重要,這樣您就可以在不向Google廣告客戶收費的情況下點擊它們。如果您在未處於測試模式的情況下點擊了太多廣告,則可能會將您的帳戶標記為無效活動。


以下是示例廣告單元,它們針對每種格式指向特定的測試廣告素材:

廣告格式樣本廣告單元ID
應用程式開啟ca-app-pub-3940256099942544/3419835294
橫幅ca-app-pub-3940256099942544/6300978111
插頁式ca-app-pub-3940256099942544/1033173712
插頁式視頻ca-app-pub-3940256099942544/8691691433
獎勵ca-app-pub-3940256099942544/5224354917
獎勵插頁式廣告ca-app-pub-3940256099942544/5354046379
本機高級ca-app-pub-3940256099942544/2247696110
原生高級視頻ca-app-pub-3940256099942544/1044960115




2021年3月15日 星期一

ionic cordova build example

Examples

ionic cordova build android
ionic cordova build android --buildConfig=build.json
ionic cordova build android --prod --release -- -- --gradleArg=-PcdvBuildMultipleApks=true
ionic cordova build android --prod --release -- -- --keystore=filename.keystore --alias=myalias
ionic cordova build android --prod --release -- -- --minSdkVersion=21
ionic cordova build android --prod --release -- -- --versionCode=55
ionic cordova build android --prod --release --buildConfig=build.json
ionic cordova build ios
ionic cordova build ios --buildConfig=build.json
ionic cordova build ios --prod --release
ionic cordova build ios --prod --release -- --developmentTeam="ABCD" --codeSignIdentity="iPhone Developer" --packageType="app-store"
ionic cordova build ios --prod --release --buildConfig=build.json

Execution failed for task ':app:stripDebugDebugSymbols'.

ionic cordova build android 


錯誤訊息:

Execution failed for task ':app:stripDebugDebugSymbols'.

> No version of NDK matched the requested version 21.0.6113669. Versions available locally: 21.3.6528147



解決:

下載對應版本NDK




ionic cordova 改為 AndroidX

修改    \platforms\android\gradle.properties


android.useAndroidX=true
android.enableJetifier=true


Build:

    ionic cordova build android


錯誤訊息:

該項目使用AndroidX依賴項,但未啟用'android.useAndroidX'屬性。在gradle.properties文件中將此屬性設置為true,然後重試。

檢測到以下AndroidX依賴項:

...


解決:

# add plugin to enable AndroidX in the project

cordova plugin add cordova-plugin-androidx


# add plugin to patch existing plugin source that uses the Android Support Library to use AndroidX

cordova plugin add cordova-plugin-androidx-adapter


2021年3月8日 星期一

Example: Ionic 5/Angular Admob

 In this tutorial we are going to see how to implement Google AdMob Ads In Ionic 5 to be able to monetize your apps using ads.

We are going to cover how to add three types of Ads:

  • Banner Ads,
  • Interstitial Ads,
  • Reward Video Ads.

Create a New Ionic 5/Angular Project

Let's start our tutorial by creating a new Ionic 5/Angular project from scratch (Optional) based on the blank template using the Ionic CLI 5:

ionic start AdmobAdsExample blank 

Next, navigate inside your Ionic 5 project folder:

cd AdmobAdsExample 

Next, install the Cordova Admob plugin and its Ionic Native 5 wrapper as follows:

ionic cordova plugin add --save cordova-plugin-admob-free        

npm install --save @ionic-native/admob-free

Next, open the src/app/app.module.ts file and import AdMobFree then add it to the list of providers:

import { AdMobFree } from '@ionic-native/admob-free';    

@NgModule({
declarations: [
    MyApp,
    HomePage   
],
imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
    MyApp,
    HomePage
],
providers: [
    StatusBar,
    SplashScreen,
    AdMobFree,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}

Showing Banner Ads in your Ionic 5 App

Next, open the src/app/app.component.ts file and add the following code:

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { AdMobFree, AdMobFreeBannerConfig } from '@ionic-native/admob-free';

import { HomePage } from '../pages/home/home';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage:any = HomePage;

constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen , private admobFree : AdMobFree ) {
    platform.ready().then(() => {
    // Okay, so the platform is ready and our plugins are available.
    // Here you can do any higher level native things you might need.
    statusBar.styleDefault();
    splashScreen.hide();
    this.showAdmobBannerAds();
    });
}
showAdmobBannerAds(){
    const bannerConfig: AdMobFreeBannerConfig = {
        isTesting: true,
        autoShow: true
    };
    this.admobFree.banner.config(bannerConfig);

    this.admobFree.banner.prepare()
    .then(() => {
        // banner Ad is ready
        // if we set autoShow to false, then we will need to call the show method here
    })
    .catch(e => console.log(e));    
    }      

}

We have injected AdMobFree and created the showAdmobBannerAds() method to show banner ads when Cordova is ready.

We have passed two configuration options:

  • isTesting : true, which tells Admob plugin to use only test ads which is the recommended option when you are still developing your app to avoid accidental clcks that may cause problems with your Google Admob account.
  • autoShow : true, which shows banner ads immediately after creating them without using the show() method.

After developing your Ionic 5 app you need to create real ads, go to AdMob portal, click "Monetize a new app" button to create a new ad unit.

Next grab your ad pubisher id and add it to configuration options as follows:

    const bannerConfig: AdMobFreeBannerConfig = {
        id: 'ca-app-pub-xxx/xxx', 
        isTesting: false,
        autoShow: true
    };

If you set autoShow to false then you need to call the show() method after preparing the banner:

    this.admobFree.banner.prepare()
    .then(() => {

        this.admobFree.banner.show()
    })
    .catch(e => console.log(e));    
    }  

You can also hide the banner using:

    this.admobFree.banner.hide()

Or you can completely remove it using:

    this.admobFree.banner.remove()        

Showing Interstitial Ads in your Ionic 5 App

You can also show Admob Interstitial ads using the following method:

showInterstitialAds(){
    const bannerConfig: AdMobFreeBannerConfig = {
    id: 'ca-app-pub-xxx/xxx',
    isTesting: false,
    autoShow: false
    };
    this.admobFree.interstitial.config(bannerConfig);

    this.admobFree.interstitial.prepare()
    .then(() => {
        this.admobFree.interstitial.show()
    })
    .catch(e => console.log(e));    
    }  

You can use the same configuration options and methods to add Interstitial Ads.

Showing Reward Video Ads in your Ionic 5 App

If you choose to display Reward Video Ads in your Ionic 5 mobile app, you can add and call the following method:

showRewardVideoAds(){
    const bannerConfig: AdMobFreeBannerConfig = {
    id: 'ca-app-pub-xxx/xxx',
    isTesting: false,
    autoShow: false
    };
    this.admobFree.rewardvideo.config(bannerConfig);

    this.admobFree.rewardvideo.prepare()
    .then(() => {
        this.admobFree.rewardvideo.show()
    })
    .catch(e => console.log(e));    
    }

如何在Ionic 5使用AdMob 中實現Google廣告

 在本教程中,看到如何在AdMob Ionic 5中實現Google廣告,以便能夠利用廣告賺錢。

介紹如何添加三種類型的廣告:

  • 橫幅廣告
  • 插頁廣告
  • 視頻廣告
  • 創建一個新的Ionic 5/ Angular項目

    讓我們通過使用Ionic CLI 5基於空白模板從頭開始創建一個新的Ionic 5/Angular項目(可選)來開始本教程:

    ionic start AdmobAdsExample blank  

    接下來,在Ionic 5項目文件夾中導航:

    cd  AdmobAdsExample

    接下來,安裝Cordova Admob插件及它Ionic Native 5包裝器,如下所示:

    ionic cordova plugin add --save cordova-plugin-admob-free 
    npm install --save @ionic-native/admob-free

    接下來,打開src/app/app.module.ts文件,並導入AdMobFree,然後將它添加到提供程序列表中:


    import { AdMobFree } from '@ionic-native/admob-free'; 

    @NgModule({
    declarations: [
     MyApp,
     HomePage 
    ],
    imports: [
     BrowserModule,
     IonicModule.forRoot(MyApp)
    ],
    bootstrap: [IonicApp],
    entryComponents: [
     MyApp,
     HomePage
    ],
    providers: [
     StatusBar,
     SplashScreen,
     AdMobFree,
     {provide: ErrorHandler, useClass: IonicErrorHandler}
    ]
    })
    export class AppModule {}    




    在Ionic 5應用程序中顯示橫幅廣告

    接下來,打開src/app/app.component.ts文件,並添加以下代碼:

    import { Component } from '@angular/core';
    import { Platform } from 'ionic-angular';
    import { StatusBar } from '@ionic-native/status-bar';
    import { SplashScreen } from '@ionic-native/splash-screen';
    import { AdMobFree, AdMobFreeBannerConfig } from '@ionic-native/admob-free';

    import { HomePage } from '../pages/home/home';
    @Component({
    templateUrl: 'app.html'
    })
    export class MyApp {
    rootPage:any = HomePage;

    constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen , private admobFree : AdMobFree ) {
     platform.ready().then(() => {
     // Okay, so the platform is ready and our plugins are available.
     // Here you can do any higher level native things you might need.
     statusBar.styleDefault();
     splashScreen.hide();
     this.showAdmobBannerAds();
     });
    }
    showAdmobBannerAds(){
     const bannerConfig: AdMobFreeBannerConfig = {
     isTesting: true,
     autoShow: true
     };
     this.admobFree.banner.config(bannerConfig);

     this.admobFree.banner.prepare()
     .then(() => {
     // banner Ad is ready
     // if we set autoShow to false, then we will need to call the show method here
     })
     .catch(e => console.log(e)); 
     } 


    我們注入了AdMobFree,並創建了showAdmobBannerAds()方法,以便在Cordova準備好時顯示橫幅廣告。

    我們傳遞了兩個配置選項:

  • isTesting:true,它告訴Admob plugin只使用測試廣告,這是你仍然開發應用程序以避免意外時的推薦選項,
  • autoShow:true,在創建標題廣告之後,立即顯示標題廣告,而不使用show()方法,
  • 開發完Ionic 5應用後,您需要製作真實的廣告,請轉到AdMob門戶,單擊"通過新應用獲利"按鈕以創建新的廣告單元。

    接下來獲取你的廣告pubisher id並將它添加到配置選項中,如下所示:

     const bannerConfig: AdMobFreeBannerConfig = {

    id: 'ca-app-pub-xxx/xxx', 

    isTesting: false,

    autoShow: true

     };


    如果將autoShow設置為false,就在準備標題後需要調用show()方法:

      this.admobFree.banner.prepare()
     .then(() => {
     this.admobFree.banner.show()
     })
     .catch(e => console.log(e)); 
     } 

    你還可以使用:

    this.admobFree.banner.hide()


    或者你可以使用:

        this.admobFree.banner.remove() 


    在您的Ionic 5應用中顯示插頁式廣告


    showInterstitialAds(){
     const bannerConfig: AdMobFreeBannerConfig = {
     id: 'ca-app-pub-xxx/xxx',
     isTesting: false,
     autoShow: false
     };
     this.admobFree.interstitial.config(bannerConfig);

     this.admobFree.interstitial.prepare()
     .then(() => {
     this.admobFree.interstitial.show()
     })
     .catch(e => console.log(e)); 
    } 


    在Ionic 5應用程序中顯示視頻廣告




    showRewardVideoAds(){
     const bannerConfig: AdMobFreeBannerConfig = {
     id: 'ca-app-pub-xxx/xxx',
     isTesting: false,
     autoShow: false
     };
     this.admobFree.rewardvideo.config(bannerConfig);

     this.admobFree.rewardvideo.prepare()
     .then(() => {
     this.admobFree.rewardvideo.show()
     })
     .catch(e => console.log(e)); 
     }




    [Q&A] Send image from ionic to asp.net core (IFormFile) web api

     [Q] We are looking to upload image from ionic to .net core web api. To achieve this we are using file transfer plugin. So, far we understoo...