-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhockeyapp.ios.ts
65 lines (51 loc) · 1.97 KB
/
hockeyapp.ios.ts
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/// <reference path="node_modules/tns-platform-declarations/ios/ios.d.ts" />
import { isIOS } from 'platform';
import { IOS, getInstance } from "./hockeyapp.common";
import * as utils from "utils/utils";
declare var BITHockeyManager: any;
const APP_ID_KEY = "HockeyAppId";
class HockeyAppIOSPlugin implements IOS {
private initDone = false;
private metricsManager : any = null;
constructor() { }
init(appId?: string): void {
if (this.initDone) {
console.log("HockeyAppIOSPlugin already initialized");
return;
}
if (!isIOS) {
return;
}
try {
if (!appId) {
let mainBundle = utils.ios.getter(NSBundle, NSBundle.mainBundle);
appId = mainBundle.infoDictionary.objectForKey(APP_ID_KEY);
}
if (!appId) {
console.error("No HockeyApp app ID was found. Please set an entry in Info.plist with key " + APP_ID_KEY);
return;
}
BITHockeyManager.sharedHockeyManager().configureWithIdentifier(appId);
BITHockeyManager.sharedHockeyManager().startManager();
BITHockeyManager.sharedHockeyManager().authenticator.authenticateInstallation();
this.metricsManager = BITHockeyManager.sharedHockeyManager().metricsManager;
this.initDone = true;
} catch (e) {
console.error('Error during init of HockeyApp', e);
}
}
trackEvent(eventName: string): void {
if (!this.metricsManager) {
console.warn("Metrics manager is not initialized, event won't be tracked");
return;
}
if (!eventName || !/^[a-zA-Z0-9_. -]+$/.test(eventName)) {
console.warn("Invalid event name, it may not appear in HockeyApp");
}
this.metricsManager.trackEventWithName(eventName)
}
}
/**
* Create new singleton instance
*/
export const HockeyApp: IOS = getInstance(HockeyAppIOSPlugin);