|
1 /* |
|
2 Licensed to the Apache Software Foundation (ASF) under one |
|
3 or more contributor license agreements. See the NOTICE file |
|
4 distributed with this work for additional information |
|
5 regarding copyright ownership. The ASF licenses this file |
|
6 to you under the Apache License, Version 2.0 (the |
|
7 "License"); you may not use this file except in compliance |
|
8 with the License. You may obtain a copy of the License at |
|
9 |
|
10 http://www.apache.org/licenses/LICENSE-2.0 |
|
11 |
|
12 Unless required by applicable law or agreed to in writing, |
|
13 software distributed under the License is distributed on an |
|
14 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|
15 KIND, either express or implied. See the License for the |
|
16 specific language governing permissions and limitations |
|
17 under the License. |
|
18 */ |
|
19 |
|
20 #include <sys/types.h> |
|
21 #include <sys/sysctl.h> |
|
22 |
|
23 #import <Cordova/CDV.h> |
|
24 #import "CDVDevice.h" |
|
25 |
|
26 @implementation UIDevice (ModelVersion) |
|
27 |
|
28 - (NSString*)modelVersion |
|
29 { |
|
30 size_t size; |
|
31 |
|
32 sysctlbyname("hw.machine", NULL, &size, NULL, 0); |
|
33 char* machine = malloc(size); |
|
34 sysctlbyname("hw.machine", machine, &size, NULL, 0); |
|
35 NSString* platform = [NSString stringWithUTF8String:machine]; |
|
36 free(machine); |
|
37 |
|
38 return platform; |
|
39 } |
|
40 |
|
41 @end |
|
42 |
|
43 @interface CDVDevice () {} |
|
44 @end |
|
45 |
|
46 @implementation CDVDevice |
|
47 |
|
48 - (void)getDeviceInfo:(CDVInvokedUrlCommand*)command |
|
49 { |
|
50 NSDictionary* deviceProperties = [self deviceProperties]; |
|
51 CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:deviceProperties]; |
|
52 |
|
53 [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; |
|
54 } |
|
55 |
|
56 - (NSDictionary*)deviceProperties |
|
57 { |
|
58 UIDevice* device = [UIDevice currentDevice]; |
|
59 NSMutableDictionary* devProps = [NSMutableDictionary dictionaryWithCapacity:4]; |
|
60 |
|
61 [devProps setObject:[device modelVersion] forKey:@"model"]; |
|
62 [devProps setObject:@"iOS" forKey:@"platform"]; |
|
63 [devProps setObject:[device systemVersion] forKey:@"version"]; |
|
64 [devProps setObject:[device uniqueAppInstanceIdentifier] forKey:@"uuid"]; |
|
65 [devProps setObject:[[self class] cordovaVersion] forKey:@"cordova"]; |
|
66 |
|
67 NSDictionary* devReturn = [NSDictionary dictionaryWithDictionary:devProps]; |
|
68 return devReturn; |
|
69 } |
|
70 |
|
71 + (NSString*)cordovaVersion |
|
72 { |
|
73 return CDV_VERSION; |
|
74 } |
|
75 |
|
76 @end |