diff --git a/.gitignore b/.gitignore index d65bfa3..bc5ffa0 100644 --- a/.gitignore +++ b/.gitignore @@ -37,13 +37,33 @@ Temporary Items .apdisk # Ionic example -./ionic/example/node_modules -./ionic/example/plugins -./ionic/example/config.xml -./ionic/example/ionic.config.json -./ionic/example/package-lock.json -./ionic/example/package.json -./ionic/example/tsconfig.json -./ionic/example/tslint.json +ionic/example/.sourcemaps/* +ionic/example/node_modules/* +ionic/example/plugins/* +ionic/example/config.xml +ionic/example/ionic.config.json +ionic/example/package-lock.json +ionic/example/package.json +ionic/example/tsconfig.json +ionic/example/tslint.json +ionic/example/resources/README\.md +ionic/example/www/* +ionic/example/src/assets/* +ionic/example/src/theme +ionic/example/platforms + +ionic/example/src/manifest\.json + +ionic/example/resources/android/splash/ + +ionic/example/resources/ + +ionic/example/src/service-worker\.js + +ionic/example/src/index\.html + +ionic/example/src/app/app\.scss + +ionic/example/src/app/main\.ts # End of https://www.gitignore.io/api/macos,apachecordova diff --git a/ionic/example/src/app/app.component.ts b/ionic/example/src/app/app.component.ts new file mode 100644 index 0000000..5283370 --- /dev/null +++ b/ionic/example/src/app/app.component.ts @@ -0,0 +1,25 @@ +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 { JPush } from '@jiguang-ionic/jpush'; + +import { HomePage } from '../pages/home/home'; +@Component({ + templateUrl: 'app.html' +}) +export class MyApp { + rootPage:any = HomePage; + + constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, jpush: JPush) { + 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(); + + jpush.init(); + jpush.setDebugMode(true); + }); + } +} diff --git a/ionic/example/src/app/app.html b/ionic/example/src/app/app.html new file mode 100644 index 0000000..7b88c96 --- /dev/null +++ b/ionic/example/src/app/app.html @@ -0,0 +1 @@ + diff --git a/ionic/example/src/app/app.module.ts b/ionic/example/src/app/app.module.ts new file mode 100644 index 0000000..ce364d8 --- /dev/null +++ b/ionic/example/src/app/app.module.ts @@ -0,0 +1,34 @@ +import { BrowserModule } from '@angular/platform-browser'; +import { ErrorHandler, NgModule } from '@angular/core'; +import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular'; +import { SplashScreen } from '@ionic-native/splash-screen'; +import { StatusBar } from '@ionic-native/status-bar'; +import { Device } from '@ionic-native/device'; +import { JPush } from '@jiguang-ionic/jpush'; + +import { MyApp } from './app.component'; +import { HomePage } from '../pages/home/home'; + +@NgModule({ + declarations: [ + MyApp, + HomePage + ], + imports: [ + BrowserModule, + IonicModule.forRoot(MyApp) + ], + bootstrap: [IonicApp], + entryComponents: [ + MyApp, + HomePage + ], + providers: [ + StatusBar, + SplashScreen, + Device, + JPush, + {provide: ErrorHandler, useClass: IonicErrorHandler} + ] +}) +export class AppModule {} diff --git a/ionic/example/src/pages/home/home.html b/ionic/example/src/pages/home/home.html new file mode 100644 index 0000000..6219446 --- /dev/null +++ b/ionic/example/src/pages/home/home.html @@ -0,0 +1,36 @@ + + + + JPush Ionic Example + + + + + + + + + Registration Id: {{registrationId}} + Get Registration Id + + + + Set tags - Tag1, Tag2 + Add tags - Tag3, Tag4 + Check tag bind state - Tag1 + Delete tags - Tag4 + Get all tags + Clean tags + + + + Set Alias - TestAlias + Get Alias + Delete Alias + + + + Trigger local notification after 5 seconds + + + diff --git a/ionic/example/src/pages/home/home.scss b/ionic/example/src/pages/home/home.scss new file mode 100644 index 0000000..d4cc8fc --- /dev/null +++ b/ionic/example/src/pages/home/home.scss @@ -0,0 +1,3 @@ +page-home { + +} diff --git a/ionic/example/src/pages/home/home.ts b/ionic/example/src/pages/home/home.ts new file mode 100644 index 0000000..b0bd0c2 --- /dev/null +++ b/ionic/example/src/pages/home/home.ts @@ -0,0 +1,132 @@ +import { Component } from '@angular/core'; +import { NavController } from 'ionic-angular'; +import { JPush } from '@jiguang-ionic/jpush'; +import { Device } from '@ionic-native/device'; + +@Component({ + selector: 'page-home', + templateUrl: 'home.html' +}) +export class HomePage { + + public registrationId: string; + + devicePlatform: string; + sequence: number = 0; + + tagResultHandler = function(result) { + var sequence: number = result.sequence; + var tags: Array = result.tags == null ? [] : result.tags; + alert('Success!' + '\nSequence: ' + sequence + '\nTags: ' + tags.toString()); + }; + + aliasResultHandler = function(result) { + var sequence: number = result.sequence; + var alias: string = result.alias; + alert('Success!' + '\nSequence: ' + sequence + '\nAlias: ' + alias); + }; + + errorHandler = function(err) { + var sequence: number = err.sequence; + var code = err.code; + alert('Error!' + '\nSequence: ' + sequence + '\nCode: ' + code); + }; + + constructor(public navCtrl: NavController, public jpush: JPush, device: Device) { + + this.devicePlatform = device.platform; + + document.addEventListener('jpush.receiveNotification', (event: any) => { + var content; + if (this.devicePlatform == 'Android') { + content = event.alert; + } else { + content = event.aps.alert; + } + console.log('Receive notification: ' + content); + }, false); + + document.addEventListener('jpush.openNotification', (event: any) => { + var content; + if (this.devicePlatform == 'Android') { + content = event.alert; + } else { + content = event.aps.alert; + } + alert('Open notification: ' + content); + }, false); + } + + getRegistrationID() { + this.jpush.getRegistrationID() + .then(rId => { + this.registrationId = rId; + }); + } + + setTags() { + this.jpush.setTags({ sequence: this.sequence++, tags: ['Tag1', 'Tag2']}) + .then(this.tagResultHandler) + .catch(this.errorHandler); + } + + addTags() { + this.jpush.addTags({ sequence: this.sequence++, tags: ['Tag3', 'Tag4']}) + .then(this.tagResultHandler) + .catch(this.errorHandler); + } + + checkTagBindState() { + this.jpush.checkTagBindState({ sequence: this.sequence++, tag: 'Tag1' }) + .then(result => { + var sequence = result.sequence; + var tag = result.tag; + var isBind = result.isBind; + alert('Sequence: ' + sequence + '\nTag: ' + tag + '\nIsBind: ' + isBind); + }).catch(this.errorHandler); + } + + deleteTags() { + this.jpush.deleteTags({ sequence: this.sequence++, tags: ['Tag4']}) + .then(this.tagResultHandler) + .catch(this.errorHandler); + } + + getAllTags() { + this.jpush.getAllTags({ sequence: this.sequence++ }) + .then(this.tagResultHandler) + .catch(this.errorHandler); + } + + cleanTags() { + this.jpush.cleanTags({ sequence: this.sequence++ }) + .then(this.tagResultHandler) + .catch(this.errorHandler); + } + + setAlias() { + this.jpush.setAlias({ sequence: this.sequence++, alias: 'TestAlias' }) + .then(this.aliasResultHandler) + .catch(this.errorHandler); + } + + getAlias() { + this.jpush.getAlias({ sequence: this.sequence++ }) + .then(this.aliasResultHandler) + .catch(this.errorHandler); + } + + deleteAlias() { + this.jpush.deleteAlias({ sequence: this.sequence++ }) + .then(this.aliasResultHandler) + .catch(this.errorHandler); + } + + addLocalNotification() { + if (this.devicePlatform == 'Android') { + this.jpush.addLocalNotification(0, 'Hello JPush', 'JPush', 1, 5000); + } else { + this.jpush.addLocalNotificationForIOS(5, 'Hello JPush', 1, 'noti1'); + } + } +}