Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(iOs) Device properties request can crash if invoked on locked device #179

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 51 additions & 8 deletions src/ios/CDVDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -68,8 +79,36 @@ - (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];
}
}

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;
Expand All @@ -87,12 +126,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])
Expand Down