Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

CDVDevice.m 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing,
  11. software distributed under the License is distributed on an
  12. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. KIND, either express or implied. See the License for the
  14. specific language governing permissions and limitations
  15. under the License.
  16. */
  17. #include <sys/types.h>
  18. #include <sys/sysctl.h>
  19. #include "TargetConditionals.h"
  20. #import <Cordova/CDV.h>
  21. #import "CDVDevice.h"
  22. @implementation UIDevice (ModelVersion)
  23. - (NSString*)modelVersion
  24. {
  25. #if TARGET_IPHONE_SIMULATOR
  26. NSString* platform = NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"];
  27. #else
  28. size_t size;
  29. sysctlbyname("hw.machine", NULL, &size, NULL, 0);
  30. char* machine = malloc(size);
  31. sysctlbyname("hw.machine", machine, &size, NULL, 0);
  32. NSString* platform = [NSString stringWithUTF8String:machine];
  33. free(machine);
  34. #endif
  35. return platform;
  36. }
  37. @end
  38. @interface CDVDevice () {}
  39. @end
  40. @implementation CDVDevice
  41. - (NSString*)uniqueAppInstanceIdentifier:(UIDevice*)device
  42. {
  43. NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
  44. static NSString* UUID_KEY = @"CDVUUID";
  45. // Check user defaults first to maintain backwards compaitibility with previous versions
  46. // which didn't user identifierForVendor
  47. NSString* app_uuid = [userDefaults stringForKey:UUID_KEY];
  48. if (app_uuid == nil) {
  49. if ([device respondsToSelector:@selector(identifierForVendor)]) {
  50. app_uuid = [[device identifierForVendor] UUIDString];
  51. } else {
  52. CFUUIDRef uuid = CFUUIDCreate(NULL);
  53. app_uuid = (__bridge_transfer NSString *)CFUUIDCreateString(NULL, uuid);
  54. CFRelease(uuid);
  55. }
  56. [userDefaults setObject:app_uuid forKey:UUID_KEY];
  57. [userDefaults synchronize];
  58. }
  59. return app_uuid;
  60. }
  61. - (void)getDeviceInfo:(CDVInvokedUrlCommand*)command
  62. {
  63. NSDictionary* deviceProperties = [self deviceProperties];
  64. CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:deviceProperties];
  65. [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
  66. }
  67. - (NSDictionary*)deviceProperties
  68. {
  69. UIDevice* device = [UIDevice currentDevice];
  70. return @{
  71. @"manufacturer": @"Apple",
  72. @"model": [device modelVersion],
  73. @"platform": @"iOS",
  74. @"version": [device systemVersion],
  75. @"uuid": [self uniqueAppInstanceIdentifier:device],
  76. @"cordova": [[self class] cordovaVersion],
  77. @"isVirtual": @([self isVirtual])
  78. };
  79. }
  80. + (NSString*)cordovaVersion
  81. {
  82. return CDV_VERSION;
  83. }
  84. - (BOOL)isVirtual
  85. {
  86. #if TARGET_OS_SIMULATOR
  87. return true;
  88. #elif TARGET_IPHONE_SIMULATOR
  89. return true;
  90. #else
  91. return false;
  92. #endif
  93. }
  94. @end