Skip to content

Commit

Permalink
feat(appcenter): add appcenter cordova sdk( analytics/crashes )
Browse files Browse the repository at this point in the history
  • Loading branch information
pengkobe committed Nov 14, 2018
1 parent dd8b2c9 commit 3ab3729
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 3 deletions.
6 changes: 6 additions & 0 deletions config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
<preference name="AutoHideSplashScreen" value="false" />
<preference name="FadeSplashScreen" value="false" />
<preference name="ShowSplashScreen" value="true" />
<preference name="APPCENTER_ANALYTICS_ENABLE_IN_JS" value="true" />
<preference name="APPCENTER_CRASHES_ALWAYS_SEND" value="false" />
<platform name="android">
<allow-intent href="market:*" />
<preference name="APP_SECRET" value="85a61209-7bb7-4692-9649-77907e85cdf9"/>
<icon density="ldpi" src="resources/android/icon/drawable-ldpi-icon.png" />
<icon density="mdpi" src="resources/android/icon/drawable-mdpi-icon.png" />
<icon density="hdpi" src="resources/android/icon/drawable-hdpi-icon.png" />
Expand All @@ -45,6 +48,7 @@
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<preference name="APP_SECRET" value="85a61209-7bb7-4692-9649-77907e85cdf9"/>
<allow-intent href="itms-apps:*" />
<icon height="57" src="resources/ios/icon/icon.png" width="57" />
<icon height="114" src="resources/ios/icon/[email protected]" width="114" />
Expand Down Expand Up @@ -106,4 +110,6 @@
<plugin name="cordova-plugin-local-notification" spec="^0.9.0-beta.2" />
<plugin name="cordova-hot-code-push-plugin" spec="^1.5.3" />
<engine name="android" spec="7.0.0" />
<plugin name="cordova-plugin-appcenter-analytics" spec="^0.2.0" />
<plugin name="cordova-plugin-appcenter-crashes" spec="^0.2.0" />
</widget>
31 changes: 31 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"@angular/pwa": "^0.8.7",
"@angular/router": "~6.1.1",
"@angular/service-worker": "~6.1.1",
"@ionic-native/app-center-analytics": "^5.0.0-beta.21",
"@ionic-native/app-center-crashes": "^5.0.0-beta.21",
"@ionic-native/background-mode": "^5.0.0-beta.21",
"@ionic-native/core": "5.0.0-beta.21",
"@ionic-native/file": "^5.0.0-beta.21",
Expand All @@ -52,6 +54,9 @@
"@ngx-translate/http-loader": "^3.0.1",
"cordova-android": "7.0.0",
"cordova-hot-code-push-plugin": "^1.5.3",
"cordova-plugin-appcenter-analytics": "^0.2.0",
"cordova-plugin-appcenter-crashes": "^0.2.0",
"cordova-plugin-appcenter-shared": "^0.2.0",
"cordova-plugin-background-mode": "^0.7.2",
"cordova-plugin-badge": "^0.8.7",
"cordova-plugin-device": "^2.0.2",
Expand Down Expand Up @@ -144,7 +149,9 @@
"APP_KEY": "e4fad56dc2d40b58d77629f7"
},
"cordova-plugin-local-notification": {},
"cordova-hot-code-push-plugin": {}
"cordova-hot-code-push-plugin": {},
"cordova-plugin-appcenter-analytics": {},
"cordova-plugin-appcenter-crashes": {}
},
"platforms": [
"android"
Expand Down
1 change: 1 addition & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export class MyApp {
if (window.cordova) {
this.updateService.checkUpdate();
this.registerBackButtonAction();
this.native.initAppCenter();
}
});

Expand Down
4 changes: 4 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { BackgroundMode } from '@ionic-native/background-mode/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { LocalNotifications } from '@ionic-native/local-notifications/ngx';
import { AppCenterAnalytics } from '@ionic-native/app-center-analytics/ngx';
import { AppCenterCrashes } from '@ionic-native/app-center-crashes/ngx';

import { EffectsModule } from '@ngrx/effects';
import { StoreModule } from '@ngrx/store';
Expand Down Expand Up @@ -56,6 +58,8 @@ import { environment } from '../environments/environment';
FileOpener,
Insomnia,
Network,
AppCenterAnalytics,
AppCenterCrashes,
LocalNotifications,
RebirthHttpModule,
// { provide: ErrorHandler, useClass: MyErrorHandler },
Expand Down
27 changes: 25 additions & 2 deletions src/app/services/native.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* - 屏幕常亮设置
* - 文件下载
* - 本地通知
* - 应用统计相关
*/

import { Injectable } from '@angular/core';
Expand All @@ -12,7 +13,8 @@ import { GlobalService } from './global.service';
import { Insomnia } from '@ionic-native/insomnia/ngx';
import { Network } from '@ionic-native/network/ngx';
import { LocalNotifications } from '@ionic-native/local-notifications/ngx';

import { AppCenterAnalytics } from '@ionic-native/app-center-analytics/ngx';
import { AppCenterCrashes } from '@ionic-native/app-center-crashes/ngx';
import {
FileTransfer,
FileTransferObject,
Expand All @@ -34,9 +36,30 @@ export class NativeService {
private toastCtrl: ToastController,
private transfer: FileTransfer,
private network: Network,
private localNotifications: LocalNotifications
private localNotifications: LocalNotifications,
private appCenterAnalytics: AppCenterAnalytics,
private appCenterCrashes: AppCenterCrashes
) {}

/**
* 初始化
*/
initAppCenter() {
this.appCenterAnalytics.setEnabled(true).then(() => {
this.appCenterAnalytics
.trackEvent('Init', { TEST: 'yipeng.ionic3' })
.then(() => {
console.log('AppCenter Analytics event tracked');
});
});

this.appCenterCrashes.setEnabled(true).then(() => {
this.appCenterCrashes.lastSessionCrashReport().then(report => {
console.log('Crash report', report);
});
});
}

initNativeService() {
this.listenInsomniaState();
this.listenNetworkState();
Expand Down

0 comments on commit 3ab3729

Please sign in to comment.