From b3a0d0333bcef8bb089f191ca751af0d0dce1aad Mon Sep 17 00:00:00 2001 From: sergey radionov Date: Tue, 26 Jul 2022 11:51:44 +0700 Subject: [PATCH 1/4] iOs: errors handling added to modelVersion --- src/ios/CDVDevice.m | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/ios/CDVDevice.m b/src/ios/CDVDevice.m index 7315489..a0dd172 100644 --- a/src/ios/CDVDevice.m +++ b/src/ios/CDVDevice.m @@ -33,11 +33,22 @@ - (NSString*)modelVersion #if TARGET_IPHONE_SIMULATOR NSString* platform = NSProcessInfo.processInfo.environment[@"SIMULATOR_MODEL_IDENTIFIER"]; #else - size_t size; + size_t size = 0; + + if(sysctlbyname("hw.machine", NULL, &size, NULL, 0) != 0) { + return nil; + } - sysctlbyname("hw.machine", NULL, &size, NULL, 0); char* machine = malloc(size); - sysctlbyname("hw.machine", machine, &size, NULL, 0); + if(!machine) { + return nil; + } + + if(sysctlbyname("hw.machine", machine, &size, NULL, 0) != 0) { + free(machine); + return nil; + } + NSString* platform = [NSString stringWithUTF8String:machine]; free(machine); #endif From b8689d33ec8c999c402d44f409794b32a3956147 Mon Sep 17 00:00:00 2001 From: sergey radionov Date: Tue, 26 Jul 2022 11:57:23 +0700 Subject: [PATCH 2/4] iOs: NSDictionary protected from nil value --- src/ios/CDVDevice.m | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ios/CDVDevice.m b/src/ios/CDVDevice.m index a0dd172..25c8de9 100644 --- a/src/ios/CDVDevice.m +++ b/src/ios/CDVDevice.m @@ -98,12 +98,16 @@ - (NSDictionary*)deviceProperties { UIDevice* device = [UIDevice currentDevice]; + NSString* modelVersion = [device modelVersion]; + NSString* systemVersion = [device systemVersion]; + NSString* uniqueId = [self uniqueAppInstanceIdentifier:device]; + return @{ @"manufacturer": @"Apple", - @"model": [device modelVersion], + @"model": modelVersion ? modelVersion : @"", @"platform": @"iOS", - @"version": [device systemVersion], - @"uuid": [self uniqueAppInstanceIdentifier:device], + @"version": systemVersion ? systemVersion : @"", + @"uuid": uniqueId ? uniqueId : @"", @"cordova": [[self class] cordovaVersion], @"isVirtual": @([self isVirtual]), @"isiOSAppOnMac": @([self isiOSAppOnMac]) From c01115a8852ed1902d196cfae6fafb5fcbfad73b Mon Sep 17 00:00:00 2001 From: sergey radionov Date: Thu, 11 Aug 2022 14:14:11 +0700 Subject: [PATCH 3/4] iOs: don't try update UserDefaults if there is nothing to set --- src/ios/CDVDevice.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ios/CDVDevice.m b/src/ios/CDVDevice.m index 25c8de9..3c316b6 100644 --- a/src/ios/CDVDevice.m +++ b/src/ios/CDVDevice.m @@ -79,8 +79,10 @@ - (NSString*)uniqueAppInstanceIdentifier:(UIDevice*)device CFRelease(uuid); } - [userDefaults setObject:app_uuid forKey:UUID_KEY]; - [userDefaults synchronize]; + if (app_uuid != nil) { + [userDefaults setObject:app_uuid forKey:UUID_KEY]; + [userDefaults synchronize]; + } } return app_uuid; From 0cdf423c961cc4ed63660fcc09e7ab52798f77a5 Mon Sep 17 00:00:00 2001 From: sergey radionov Date: Tue, 30 Aug 2022 19:16:08 +0700 Subject: [PATCH 4/4] iOs: backup app id in file without protection to allow acess to it from locked phone --- src/ios/CDVDevice.m | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/ios/CDVDevice.m b/src/ios/CDVDevice.m index 3c316b6..5231ff0 100644 --- a/src/ios/CDVDevice.m +++ b/src/ios/CDVDevice.m @@ -85,6 +85,32 @@ - (NSString*)uniqueAppInstanceIdentifier:(UIDevice*)device } } + NSFileManager* fileManager = [NSFileManager defaultManager]; + NSURL* app_support_dir_url = + [[fileManager URLsForDirectory: NSApplicationSupportDirectory + inDomains: NSUserDomainMask] firstObject]; + NSURL* app_uuid_file_url = + [app_support_dir_url URLByAppendingPathComponent: UUID_KEY]; + NSString* backup_app_uuid = + [NSString stringWithContentsOfURL: app_uuid_file_url + encoding: NSASCIIStringEncoding error: NULL]; + + if(app_uuid == nil) { + app_uuid = backup_app_uuid; + } else if(backup_app_uuid == nil || ![app_uuid isEqualToString: backup_app_uuid]) { + NSData* app_uuid_data = [app_uuid dataUsingEncoding: NSASCIIStringEncoding]; + [fileManager createDirectoryAtURL: app_support_dir_url + withIntermediateDirectories: YES + attributes: nil + error: NULL]; + [app_uuid_data writeToURL:app_uuid_file_url + options: NSDataWritingFileProtectionNone + error: nil]; + [app_uuid_file_url setResourceValue: @YES + forKey: NSURLIsExcludedFromBackupKey + error: NULL]; + } + return app_uuid; }