forked from NativeScript/NativeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplatform.ios.ts
More file actions
128 lines (103 loc) · 3.1 KB
/
platform.ios.ts
File metadata and controls
128 lines (103 loc) · 3.1 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* tslint:disable:class-name */
import definition = require("platform");
export module platformNames {
export var android = "Android";
export var ios = "iOS";
}
class Device implements definition.Device {
private _model: string;
private _osVersion: string;
private _sdkVersion: string;
private _deviceType: string;
private _language: string;
private _region: string;
get manufacturer(): string {
return "Apple";
}
get os(): string {
return platformNames.ios;
}
get osVersion(): string {
if (!this._osVersion) {
this._osVersion = UIDevice.currentDevice().systemVersion;
}
return this._osVersion;
}
get model(): string {
if (!this._model) {
this._model = UIDevice.currentDevice().model;
}
return this._model;
}
get sdkVersion(): string {
if (!this._sdkVersion) {
this._sdkVersion = UIDevice.currentDevice().systemVersion;
}
return this._sdkVersion;
}
get deviceType(): string {
if (!this._deviceType) {
var enums = require("ui/enums");
if (UIDevice.currentDevice().userInterfaceIdiom === UIUserInterfaceIdiom.UIUserInterfaceIdiomPhone) {
this._deviceType = enums.DeviceType.Phone;
}
else {
this._deviceType = enums.DeviceType.Tablet;
}
}
return this._deviceType;
}
get uuid(): string {
var userDefaults = NSUserDefaults.standardUserDefaults();
var uuid_key = "TNSUUID";
var app_uuid = userDefaults.stringForKey(uuid_key);
if (!app_uuid) {
var uuidRef = CFUUIDCreate(kCFAllocatorDefault);
app_uuid = CFUUIDCreateString(kCFAllocatorDefault, uuidRef);
userDefaults.setObjectForKey(app_uuid, uuid_key);
userDefaults.synchronize();
}
return app_uuid;
}
get language(): string {
if (!this._language) {
var languages = NSLocale.preferredLanguages();
this._language = languages[0];
}
return this._language;
}
get region(): string {
if(!this._region) {
this._region = NSLocale.currentLocale().objectForKey(NSLocaleCountryCode);
}
return this._region;
}
}
class MainScreen implements definition.ScreenMetrics {
private _screen: UIScreen;
private get screen(): UIScreen {
if (!this._screen) {
this._screen = UIScreen.mainScreen();
}
return this._screen;
}
get widthPixels(): number {
return this.widthDIPs * this.scale;
}
get heightPixels(): number {
return this.heightDIPs * this.scale;
}
get scale(): number {
return this.screen.scale;
}
get widthDIPs(): number {
return this.screen.bounds.size.width;
}
get heightDIPs(): number {
return this.screen.bounds.size.height;
}
}
export var device: definition.Device = new Device();
export module screen {
export var mainScreen = new MainScreen();
}