Skip to content

Commit dd79f18

Browse files
committed
ステップ2「アプリにネイティブ機能をつけよう」
Cordovaプラグイン「バッジで通知数を知らせよう」
1 parent 0267182 commit dd79f18

File tree

11 files changed

+47
-5
lines changed

11 files changed

+47
-5
lines changed

android/app/capacitor.build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ android {
99

1010
apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
1111
dependencies {
12-
1312
implementation project(':rdlabo-capacitor-admob')
1413

1514
}
16-
15+
apply from: "../../node_modules/cordova-plugin-badge/src/android/badge.gradle"
1716

1817
if (hasProperty('postBuildExtras')) {
1918
postBuildExtras()

android/app/src/main/res/xml/config.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22
<widget version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
33
<access origin="*" />
44

5+
<feature name="Badge">
6+
<param name="android-package" value="de.appplant.cordova.plugin.badge.Badge"/>
7+
</feature>
8+
59
</widget>

capacitor.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"npmClient": "yarn",
66
"webDir": "www",
77
"server": {
8-
"url": "http://192.168.0.17:8100"
8+
"url": "http://localhost:8100"
99
}
1010
}

ios/App/App/capacitor.config.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
"appName": "native-tutorial",
44
"bundledWebRuntime": false,
55
"npmClient": "yarn",
6-
"webDir": "www"
6+
"webDir": "www",
7+
"server": {
8+
"url": "http://localhost:8100"
9+
}
710
}

ios/App/App/config.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22
<widget version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
33
<access origin="*" />
44

5+
<feature name="Badge">
6+
<param name="ios-package" value="APPBadge"/>
7+
</feature>
8+
59
</widget>

ios/App/Podfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def capacitor_pods
1111
pod 'Capacitor', :path => '../../node_modules/@capacitor/ios'
1212
pod 'CapacitorCordova', :path => '../../node_modules/@capacitor/ios'
1313
pod 'RdlaboCapacitorAdmob', :path => '../../node_modules/@rdlabo/capacitor-admob'
14+
pod 'CordovaPlugins', :path => '../capacitor-cordova-ios-plugins'
1415
# Do not delete
1516
end
1617

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
"@capacitor/android": "^1.1.1",
2424
"@capacitor/core": "1.1.1",
2525
"@capacitor/ios": "^1.1.1",
26+
"@ionic-native/badge": "^5.13.0",
2627
"@ionic-native/core": "^5.0.0",
2728
"@ionic-native/splash-screen": "^5.0.0",
2829
"@ionic-native/status-bar": "^5.0.0",
2930
"@ionic/angular": "^4.7.1",
3031
"@rdlabo/capacitor-admob": "^0.1.4",
32+
"cordova-plugin-badge": "^0.8.8",
3133
"core-js": "^2.5.4",
3234
"rxjs": "~6.5.1",
3335
"tslib": "^1.9.0",

src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { RouteReuseStrategy } from '@angular/router';
55
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
66
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
77
import { StatusBar } from '@ionic-native/status-bar/ngx';
8+
import { Badge } from '@ionic-native/badge/ngx';
89

910
import { AppRoutingModule } from './app-routing.module';
1011
import { AppComponent } from './app.component';
@@ -16,6 +17,7 @@ import { AppComponent } from './app.component';
1617
providers: [
1718
StatusBar,
1819
SplashScreen,
20+
Badge,
1921
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
2022
],
2123
bootstrap: [AppComponent]

src/app/tab2/tab2.page.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@
1111
<ion-button (click)="displayAdMob()" *ngIf="!isAdsense" color="primary">広告をだす</ion-button>
1212
<ion-button (click)="hideAdMob()" *ngIf="isAdsense" color="danger">広告を隠す</ion-button>
1313
</div>
14+
15+
<ion-list>
16+
<ion-list-header>バッジの操作</ion-list-header>
17+
<ion-item button="true" (click)="upBadge()">バッジを増やす</ion-item>
18+
<ion-item button="true" (click)="clearBadge()">バッジクリア</ion-item>
19+
</ion-list>
1420
</ion-content>

src/app/tab2/tab2.page.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Component } from '@angular/core';
22
import { Plugins } from '@capacitor/core';
33
import { AdOptions, AdSize, AdPosition } from '@rdlabo/capacitor-admob';
4+
import { Badge } from '@ionic-native/badge/ngx';
45

56
@Component({
67
selector: 'app-tab2',
@@ -9,7 +10,15 @@ import { AdOptions, AdSize, AdPosition } from '@rdlabo/capacitor-admob';
910
})
1011
export class Tab2Page {
1112
isAdsense = false;
12-
constructor() {}
13+
constructor(public badge: Badge) {}
14+
15+
upBadge() {
16+
this.badge.increase(1);
17+
}
18+
19+
clearBadge() {
20+
this.badge.clear();
21+
}
1322

1423
displayAdMob() {
1524
const options: AdOptions = {

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,13 @@
341341
resolved "https://registry.yarnpkg.com/@capacitor/ios/-/ios-1.1.1.tgz#db1419114e610b8c60513151f57e6f14e7912bac"
342342
integrity sha512-6JCNWDY7E+Tt9mkzflwlK9tHl2qcPUgazZC0/aBte9lBEDpmzGPbTlHoiYeKTIqfhQeU7Qk8g6QabCx6vNzJpQ==
343343

344+
"@ionic-native/badge@^5.13.0":
345+
version "5.13.0"
346+
resolved "https://registry.yarnpkg.com/@ionic-native/badge/-/badge-5.13.0.tgz#b4f0fa4d8eb9f7441f010296a5d31cb59c98ba3a"
347+
integrity sha512-W/cLQK04tAiyggQfSKIJH16zXF1pWtmSMie3lXT1RJB7RYxXpKirOGikGUT2bj7f1y87cgrZW5l7JaCkIKnJ5A==
348+
dependencies:
349+
"@types/cordova" latest
350+
344351
"@ionic-native/core@^5.0.0":
345352
version "5.13.0"
346353
resolved "https://registry.yarnpkg.com/@ionic-native/core/-/core-5.13.0.tgz#9d4068ae58334a4589178d135cfe7abdbad5003a"
@@ -1923,6 +1930,11 @@ [email protected]:
19231930
serialize-javascript "^1.7.0"
19241931
webpack-log "^2.0.0"
19251932

1933+
cordova-plugin-badge@^0.8.8:
1934+
version "0.8.8"
1935+
resolved "https://registry.yarnpkg.com/cordova-plugin-badge/-/cordova-plugin-badge-0.8.8.tgz#0924018699b48f92dd3b33615452737582144c96"
1936+
integrity sha512-RhIBtd5xhD/iLnxjt35jvOae28oNW/wtMZBOmQR3Rf0y4wirvA1bpAZEhBoFqL+rZGhsd6ddOdQXdex1T0DRyQ==
1937+
19261938
19271939
version "3.1.4"
19281940
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.1.4.tgz#3a2837fc48e582e1ae25907afcd6cf03b0cc7a07"

0 commit comments

Comments
 (0)