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

Thu, 04 Jun 2015 14:50:33 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 04 Jun 2015 14:50:33 +0200
changeset 0
e8ccd40d0ef6
permissions
-rw-r--r--

Genesis of lecture sources for Droidcon Berlin 2015 in Postbahnhof.

     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
    10  http://www.apache.org/licenses/LICENSE-2.0
    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  */
    20 #include <sys/types.h>
    21 #include <sys/sysctl.h>
    23 #import <Cordova/CDV.h>
    24 #import "CDVDevice.h"
    26 @implementation UIDevice (ModelVersion)
    28 - (NSString*)modelVersion
    29 {
    30     size_t size;
    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);
    38     return platform;
    39 }
    41 @end
    43 @interface CDVDevice () {}
    44 @end
    46 @implementation CDVDevice
    48 - (void)getDeviceInfo:(CDVInvokedUrlCommand*)command
    49 {
    50     NSDictionary* deviceProperties = [self deviceProperties];
    51     CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:deviceProperties];
    53     [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
    54 }
    56 - (NSDictionary*)deviceProperties
    57 {
    58     UIDevice* device = [UIDevice currentDevice];
    59     NSMutableDictionary* devProps = [NSMutableDictionary dictionaryWithCapacity:4];
    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"];
    67     NSDictionary* devReturn = [NSDictionary dictionaryWithDictionary:devProps];
    68     return devReturn;
    69 }
    71 + (NSString*)cordovaVersion
    72 {
    73     return CDV_VERSION;
    74 }
    76 @end

mercurial