Touchgui/plugins/org.apache.cordova.device/src/ios/CDVDevice.m

changeset 0
e8ccd40d0ef6
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Touchgui/plugins/org.apache.cordova.device/src/ios/CDVDevice.m	Thu Jun 04 14:50:33 2015 +0200
     1.3 @@ -0,0 +1,76 @@
     1.4 +/*
     1.5 + Licensed to the Apache Software Foundation (ASF) under one
     1.6 + or more contributor license agreements.  See the NOTICE file
     1.7 + distributed with this work for additional information
     1.8 + regarding copyright ownership.  The ASF licenses this file
     1.9 + to you under the Apache License, Version 2.0 (the
    1.10 + "License"); you may not use this file except in compliance
    1.11 + with the License.  You may obtain a copy of the License at
    1.12 +
    1.13 + http://www.apache.org/licenses/LICENSE-2.0
    1.14 +
    1.15 + Unless required by applicable law or agreed to in writing,
    1.16 + software distributed under the License is distributed on an
    1.17 + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    1.18 + KIND, either express or implied.  See the License for the
    1.19 + specific language governing permissions and limitations
    1.20 + under the License.
    1.21 + */
    1.22 +
    1.23 +#include <sys/types.h>
    1.24 +#include <sys/sysctl.h>
    1.25 +
    1.26 +#import <Cordova/CDV.h>
    1.27 +#import "CDVDevice.h"
    1.28 +
    1.29 +@implementation UIDevice (ModelVersion)
    1.30 +
    1.31 +- (NSString*)modelVersion
    1.32 +{
    1.33 +    size_t size;
    1.34 +
    1.35 +    sysctlbyname("hw.machine", NULL, &size, NULL, 0);
    1.36 +    char* machine = malloc(size);
    1.37 +    sysctlbyname("hw.machine", machine, &size, NULL, 0);
    1.38 +    NSString* platform = [NSString stringWithUTF8String:machine];
    1.39 +    free(machine);
    1.40 +
    1.41 +    return platform;
    1.42 +}
    1.43 +
    1.44 +@end
    1.45 +
    1.46 +@interface CDVDevice () {}
    1.47 +@end
    1.48 +
    1.49 +@implementation CDVDevice
    1.50 +
    1.51 +- (void)getDeviceInfo:(CDVInvokedUrlCommand*)command
    1.52 +{
    1.53 +    NSDictionary* deviceProperties = [self deviceProperties];
    1.54 +    CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:deviceProperties];
    1.55 +
    1.56 +    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
    1.57 +}
    1.58 +
    1.59 +- (NSDictionary*)deviceProperties
    1.60 +{
    1.61 +    UIDevice* device = [UIDevice currentDevice];
    1.62 +    NSMutableDictionary* devProps = [NSMutableDictionary dictionaryWithCapacity:4];
    1.63 +
    1.64 +    [devProps setObject:[device modelVersion] forKey:@"model"];
    1.65 +    [devProps setObject:@"iOS" forKey:@"platform"];
    1.66 +    [devProps setObject:[device systemVersion] forKey:@"version"];
    1.67 +    [devProps setObject:[device uniqueAppInstanceIdentifier] forKey:@"uuid"];
    1.68 +    [devProps setObject:[[self class] cordovaVersion] forKey:@"cordova"];
    1.69 +
    1.70 +    NSDictionary* devReturn = [NSDictionary dictionaryWithDictionary:devProps];
    1.71 +    return devReturn;
    1.72 +}
    1.73 +
    1.74 ++ (NSString*)cordovaVersion
    1.75 +{
    1.76 +    return CDV_VERSION;
    1.77 +}
    1.78 +
    1.79 +@end

mercurial