add device info collector
This commit is contained in:
1 parent
4140922530
commit
1c3886e10c
4 files changed
+177
No files matched your search
@@ -5,6 +5,8 @@
|
||||
#import <NetworkExtension/NetworkExtension.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
static NSString * const BluememeDeviceKeyDefaultsKey = @"bluememe_utils_device_key";
|
||||
|
||||
@interface CDVBluememeUtils ()
|
||||
@property (nonatomic, copy) NSString *notificationCallbackId;
|
||||
@property (nonatomic, strong) NSDictionary *initialNotification;
|
||||
@@ -36,6 +38,33 @@
|
||||
[self applyWifiCommand:command defaultJoinOnce:YES];
|
||||
}
|
||||
|
||||
- (void)getDeviceInfo:(CDVInvokedUrlCommand *)command
|
||||
{
|
||||
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
|
||||
NSString *bundleIdentifier = [self safeString:[[NSBundle mainBundle] bundleIdentifier]];
|
||||
NSString *appVersion = [self safeString:[infoDictionary objectForKey:@"CFBundleShortVersionString"]];
|
||||
NSString *buildNumber = [self safeString:[infoDictionary objectForKey:@"CFBundleVersion"]];
|
||||
UIDevice *device = [UIDevice currentDevice];
|
||||
NSLocale *locale = [NSLocale currentLocale];
|
||||
NSString *localeIdentifier = [self safeString:[locale localeIdentifier]];
|
||||
NSString *timeZone = [self safeString:[[NSTimeZone localTimeZone] name]];
|
||||
|
||||
NSDictionary *result = @{
|
||||
@"deviceKey": [self getOrCreateDeviceKey],
|
||||
@"platform": @"iOS",
|
||||
@"appIdentifier": bundleIdentifier,
|
||||
@"appVersion": appVersion,
|
||||
@"buildNumber": buildNumber,
|
||||
@"osVersion": [self safeString:device.systemVersion],
|
||||
@"systemName": [self safeString:device.systemName],
|
||||
@"deviceModel": [self safeString:device.model],
|
||||
@"model": [self safeString:device.model],
|
||||
@"locale": localeIdentifier,
|
||||
@"timeZone": timeZone
|
||||
};
|
||||
[self sendSuccessForCommand:command dictionary:result];
|
||||
}
|
||||
|
||||
- (void)removeWifi:(CDVInvokedUrlCommand *)command
|
||||
{
|
||||
NSDictionary *options = [self firstDictionaryArgument:command];
|
||||
@@ -446,6 +475,20 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response
|
||||
return @"";
|
||||
}
|
||||
|
||||
- (NSString *)safeString:(id)value
|
||||
{
|
||||
if ([value isKindOfClass:[NSString class]]) {
|
||||
return value;
|
||||
}
|
||||
if ([value respondsToSelector:@selector(stringValue)]) {
|
||||
return [value stringValue];
|
||||
}
|
||||
if ([value respondsToSelector:@selector(description)]) {
|
||||
return [value description];
|
||||
}
|
||||
return @"";
|
||||
}
|
||||
|
||||
- (BOOL)boolFromDictionary:(NSDictionary *)dictionary key:(NSString *)key defaultValue:(BOOL)defaultValue
|
||||
{
|
||||
id value = dictionary[key];
|
||||
@@ -473,6 +516,20 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response
|
||||
return @"";
|
||||
}
|
||||
|
||||
- (NSString *)getOrCreateDeviceKey
|
||||
{
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
NSString *existing = [defaults stringForKey:BluememeDeviceKeyDefaultsKey];
|
||||
if (existing.length > 0) {
|
||||
return existing;
|
||||
}
|
||||
|
||||
NSString *generated = [[NSUUID UUID] UUIDString];
|
||||
[defaults setObject:generated forKey:BluememeDeviceKeyDefaultsKey];
|
||||
[defaults synchronize];
|
||||
return generated;
|
||||
}
|
||||
|
||||
- (void)sendSuccessForCommand:(CDVInvokedUrlCommand *)command dictionary:(NSDictionary *)dictionary
|
||||
{
|
||||
CDVPluginResult *result = dictionary == nil
|
||||
|
||||
Reference in new issue
Block a user