Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
15747 anikendra 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
- (NSString*)uniqueAppInstanceIdentifier:(UIDevice*)device
49
{
50
    NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
51
    static NSString* UUID_KEY = @"CDVUUID";
52
 
53
    NSString* app_uuid = [userDefaults stringForKey:UUID_KEY];
54
 
55
    if (app_uuid == nil) {
56
        CFUUIDRef uuidRef = CFUUIDCreate(kCFAllocatorDefault);
57
        CFStringRef uuidString = CFUUIDCreateString(kCFAllocatorDefault, uuidRef);
58
 
59
        app_uuid = [NSString stringWithString:(__bridge NSString*)uuidString];
60
        [userDefaults setObject:app_uuid forKey:UUID_KEY];
61
        [userDefaults synchronize];
62
 
63
        CFRelease(uuidString);
64
        CFRelease(uuidRef);
65
    }
66
 
67
    return app_uuid;
68
}
69
 
70
- (void)getDeviceInfo:(CDVInvokedUrlCommand*)command
71
{
72
    NSDictionary* deviceProperties = [self deviceProperties];
73
    CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:deviceProperties];
74
 
75
    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
76
}
77
 
78
- (NSDictionary*)deviceProperties
79
{
80
    UIDevice* device = [UIDevice currentDevice];
81
    NSMutableDictionary* devProps = [NSMutableDictionary dictionaryWithCapacity:4];
82
 
83
    [devProps setObject:@"Apple" forKey:@"manufacturer"];
84
    [devProps setObject:[device modelVersion] forKey:@"model"];
85
    [devProps setObject:@"iOS" forKey:@"platform"];
86
    [devProps setObject:[device systemVersion] forKey:@"version"];
87
    [devProps setObject:[self uniqueAppInstanceIdentifier:device] forKey:@"uuid"];
88
    [devProps setObject:[[self class] cordovaVersion] forKey:@"cordova"];
89
 
90
    NSDictionary* devReturn = [NSDictionary dictionaryWithDictionary:devProps];
91
    return devReturn;
92
}
93
 
94
+ (NSString*)cordovaVersion
95
{
96
    return CDV_VERSION;
97
}
98
 
99
@end