Commit 5af3b557e475444c376af10a0dba320d05ba6527
1 parent
d5f7fd2f
CFUUID修改
Showing
6 changed files
with
112 additions
and
36 deletions
CNLiveScioLive.xcodeproj/project.pbxproj
| ... | ... | @@ -7,6 +7,7 @@ |
| 7 | 7 | objects = { |
| 8 | 8 | |
| 9 | 9 | /* Begin PBXBuildFile section */ |
| 10 | + 0802446D2624267800BD68E8 /* SdkMgr.m in Sources */ = {isa = PBXBuildFile; fileRef = 0802446C2624267800BD68E8 /* SdkMgr.m */; }; | |
| 10 | 11 | 080AB4C6217AD4F4008BA78F /* TemplateShareManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 080AB4C5217AD4F4008BA78F /* TemplateShareManager.m */; }; |
| 11 | 12 | 080AB4C7217AD4F4008BA78F /* TemplateShareManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 080AB4C5217AD4F4008BA78F /* TemplateShareManager.m */; }; |
| 12 | 13 | 080AB4C8217AD4F4008BA78F /* TemplateShareManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 080AB4C5217AD4F4008BA78F /* TemplateShareManager.m */; }; |
| ... | ... | @@ -754,6 +755,8 @@ |
| 754 | 755 | /* End PBXCopyFilesBuildPhase section */ |
| 755 | 756 | |
| 756 | 757 | /* Begin PBXFileReference section */ |
| 758 | + 0802446B2624267800BD68E8 /* SdkMgr.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SdkMgr.h; sourceTree = "<group>"; }; | |
| 759 | + 0802446C2624267800BD68E8 /* SdkMgr.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SdkMgr.m; sourceTree = "<group>"; }; | |
| 757 | 760 | 080AB4C4217AD4F4008BA78F /* TemplateShareManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TemplateShareManager.h; sourceTree = "<group>"; }; |
| 758 | 761 | 080AB4C5217AD4F4008BA78F /* TemplateShareManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TemplateShareManager.m; sourceTree = "<group>"; }; |
| 759 | 762 | 083847DF215C5DDD00186618 /* VPImageCropperViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VPImageCropperViewController.h; sourceTree = "<group>"; }; |
| ... | ... | @@ -1279,6 +1282,15 @@ |
| 1279 | 1282 | /* End PBXFrameworksBuildPhase section */ |
| 1280 | 1283 | |
| 1281 | 1284 | /* Begin PBXGroup section */ |
| 1285 | + 0802446A262425DB00BD68E8 /* DeviceUUID */ = { | |
| 1286 | + isa = PBXGroup; | |
| 1287 | + children = ( | |
| 1288 | + 0802446B2624267800BD68E8 /* SdkMgr.h */, | |
| 1289 | + 0802446C2624267800BD68E8 /* SdkMgr.m */, | |
| 1290 | + ); | |
| 1291 | + path = DeviceUUID; | |
| 1292 | + sourceTree = "<group>"; | |
| 1293 | + }; | |
| 1282 | 1294 | 080AB4BE217AD457008BA78F /* ShareTool */ = { |
| 1283 | 1295 | isa = PBXGroup; |
| 1284 | 1296 | children = ( |
| ... | ... | @@ -2014,6 +2026,7 @@ |
| 2014 | 2026 | 08C08FCF214FA01B00E23D16 /* Tools */ = { |
| 2015 | 2027 | isa = PBXGroup; |
| 2016 | 2028 | children = ( |
| 2029 | + 0802446A262425DB00BD68E8 /* DeviceUUID */, | |
| 2017 | 2030 | 08C721A924CAC9B700970100 /* SDCycleScrollView */, |
| 2018 | 2031 | 080AB4BE217AD457008BA78F /* ShareTool */, |
| 2019 | 2032 | 08585DD7215B70DA00FC2CA2 /* JSONKit */, |
| ... | ... | @@ -3067,6 +3080,7 @@ |
| 3067 | 3080 | 08940D752154EB2C00F85DB6 /* UILabel+TextAlign.m in Sources */, |
| 3068 | 3081 | 08585D83215B4C7200FC2CA2 /* PGDatePicker+DateAndTime.m in Sources */, |
| 3069 | 3082 | 08585CF9215B3AA900FC2CA2 /* ArticleTableViewCell.m in Sources */, |
| 3083 | + 0802446D2624267800BD68E8 /* SdkMgr.m in Sources */, | |
| 3070 | 3084 | C3A6D061215278CE00FB7759 /* CNLiveForgotPasswordViewController.m in Sources */, |
| 3071 | 3085 | 084ACE272154C6980089E035 /* CNLiveNewsNoPicTableViewCell.m in Sources */, |
| 3072 | 3086 | 08585CF0215B3AA900FC2CA2 /* SearchHistoryTableViewCell.m in Sources */, | ... | ... |
CNLiveScioLive/Pages/Login/Controller/CNLiveLoginViewController.m
| ... | ... | @@ -16,6 +16,7 @@ |
| 16 | 16 | #import <AuthenticationServices/AuthenticationServices.h> |
| 17 | 17 | #import <CNLiveRequestBastKit/CNLiveNetworking.h> |
| 18 | 18 | #import "NSString+Validation.h" |
| 19 | +#import "SdkMgr.h" | |
| 19 | 20 | |
| 20 | 21 | @interface CNLiveLoginViewController ()<ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding> |
| 21 | 22 | @property (nonatomic, strong) CNLiveLoginInputView *account; |
| ... | ... | @@ -472,7 +473,7 @@ |
| 472 | 473 | [mDict setValue:@"i" forKey:@"plat"]; |
| 473 | 474 | [mDict setValue:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] forKey:@"ver"]; |
| 474 | 475 | [mDict setObject:CNLiveAppId forKey:@"appId"]; |
| 475 | - [mDict setValue:[NSString uuid] forKey:@"uuid"]; | |
| 476 | + [mDict setValue:[SdkMgr getDeviceUUID] forKey:@"uuid"]; | |
| 476 | 477 | |
| 477 | 478 | [CNLiveNetworking setupDefaultParam:mDict]; |
| 478 | 479 | [CNLiveNetworking setupShowResult:NO]; | ... | ... |
CNLiveScioLive/Pages/Tools/DeviceUUID/SdkMgr.h
0 → 100644
| 1 | +// | |
| 2 | +// SdkMgr.h | |
| 3 | +// CNLiveScioLive | |
| 4 | +// | |
| 5 | +// Created by CNLive on 2021/4/12. | |
| 6 | +// Copyright © 2021 CNLive. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import <Foundation/Foundation.h> | |
| 10 | + | |
| 11 | +NS_ASSUME_NONNULL_BEGIN | |
| 12 | + | |
| 13 | +@interface SdkMgr : NSObject | |
| 14 | ++(NSString *)getDeviceUUID; | |
| 15 | +@end | |
| 16 | + | |
| 17 | +NS_ASSUME_NONNULL_END | ... | ... |
CNLiveScioLive/Pages/Tools/DeviceUUID/SdkMgr.m
0 → 100644
| 1 | +// | |
| 2 | +// SdkMgr.m | |
| 3 | +// CNLiveScioLive | |
| 4 | +// | |
| 5 | +// Created by CNLive on 2021/4/12. | |
| 6 | +// Copyright © 2021 CNLive. All rights reserved. | |
| 7 | +// | |
| 8 | + | |
| 9 | +#import "SdkMgr.h" | |
| 10 | + | |
| 11 | +@implementation SdkMgr | |
| 12 | +NSString * const KEY_UDID_INSTEAD = @"com.app.uuid.test"; | |
| 13 | + | |
| 14 | ++(NSString *)getDeviceUUID{ | |
| 15 | + NSString *getUDIDInKeychain = (NSString *)[SdkMgr load:KEY_UDID_INSTEAD]; | |
| 16 | + if (!getUDIDInKeychain ||[getUDIDInKeychain isEqualToString:@""]||[getUDIDInKeychain isKindOfClass:[NSNull class]]) { | |
| 17 | + CFUUIDRef puuid = CFUUIDCreate( nil ); | |
| 18 | + CFStringRef uuidString = CFUUIDCreateString( nil, puuid ); | |
| 19 | + NSString * result = (NSString *)CFBridgingRelease(CFStringCreateCopy( NULL, uuidString)); | |
| 20 | + CFRelease(puuid); | |
| 21 | + CFRelease(uuidString); | |
| 22 | + | |
| 23 | + //去掉横线,保留32位长度 | |
| 24 | + NSString *rst = [result stringByReplacingOccurrencesOfString:@"-" withString:@""]; | |
| 25 | + [SdkMgr save:KEY_UDID_INSTEAD data:rst]; | |
| 26 | + getUDIDInKeychain = (NSString *)[SdkMgr load:KEY_UDID_INSTEAD]; | |
| 27 | + } | |
| 28 | + return getUDIDInKeychain; | |
| 29 | +} | |
| 30 | + | |
| 31 | +#pragma mark - private | |
| 32 | + | |
| 33 | ++ (NSMutableDictionary *)getKeychainQuery:(NSString *)service { | |
| 34 | + return [NSMutableDictionary dictionaryWithObjectsAndKeys: | |
| 35 | + (id)kSecClassGenericPassword,(id)kSecClass, | |
| 36 | + service, (id)kSecAttrService, | |
| 37 | + service, (id)kSecAttrAccount, | |
| 38 | + (id)kSecAttrAccessibleAfterFirstUnlock,(id)kSecAttrAccessible, | |
| 39 | + nil]; | |
| 40 | +} | |
| 41 | + | |
| 42 | ++ (void)save:(NSString *)service data:(id)data { | |
| 43 | + //Get search dictionary | |
| 44 | + NSMutableDictionary *keychainQuery = [self getKeychainQuery:service]; | |
| 45 | + //Delete old item before add new item | |
| 46 | + SecItemDelete((CFDictionaryRef)keychainQuery); | |
| 47 | + //Add new object to search dictionary(Attention:the data format) | |
| 48 | + [keychainQuery setObject:[NSKeyedArchiver archivedDataWithRootObject:data] forKey:(id)kSecValueData]; | |
| 49 | + //Add item to keychain with the search dictionary | |
| 50 | + SecItemAdd((CFDictionaryRef)keychainQuery, NULL); | |
| 51 | +} | |
| 52 | + | |
| 53 | ++ (id)load:(NSString *)service { | |
| 54 | + id ret = nil; | |
| 55 | + NSMutableDictionary *keychainQuery = [self getKeychainQuery:service]; | |
| 56 | + //Configure the search setting | |
| 57 | + //Since in our simple case we are expecting only a single attribute to be returned (the password) we can set the attribute kSecReturnData to kCFBooleanTrue | |
| 58 | + [keychainQuery setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnData]; | |
| 59 | + [keychainQuery setObject:(id)kSecMatchLimitOne forKey:(id)kSecMatchLimit]; | |
| 60 | + CFDataRef keyData = NULL; | |
| 61 | + if (SecItemCopyMatching((CFDictionaryRef)keychainQuery, (CFTypeRef *)&keyData) == noErr) { | |
| 62 | + @try { | |
| 63 | + ret = [NSKeyedUnarchiver unarchiveObjectWithData:(__bridge NSData *)(keyData)]; | |
| 64 | + } @catch (NSException *e) { | |
| 65 | + NSLog(@"Unarchive of %@ failed: %@", service, e); | |
| 66 | + } @finally { | |
| 67 | + } | |
| 68 | + } | |
| 69 | + if (keyData) | |
| 70 | + CFRelease(keyData); | |
| 71 | + return ret; | |
| 72 | +} | |
| 73 | + | |
| 74 | ++ (void)delete:(NSString *)service { | |
| 75 | + NSMutableDictionary *keychainQuery = [self getKeychainQuery:service]; | |
| 76 | + SecItemDelete((CFDictionaryRef)keychainQuery); | |
| 77 | +} | |
| 78 | +@end | ... | ... |
CNLiveScioLive/Pages/Tools/ValidationTool/NSString+Validation.h
CNLiveScioLive/Pages/Tools/ValidationTool/NSString+Validation.m
| ... | ... | @@ -373,38 +373,5 @@ |
| 373 | 373 | |
| 374 | 374 | |
| 375 | 375 | } |
| 376 | -+ (NSString *)uuid{ | |
| 377 | - NSString *uid = @""; | |
| 378 | - NSString *uidKey = @"kCNLiveUserDefaultsUIDKey"; | |
| 379 | - NSUserDefaults *defauts = [NSUserDefaults standardUserDefaults]; | |
| 380 | - if ([defauts objectForKey:uidKey]) { | |
| 381 | - uid = [[defauts objectForKey:uidKey] copy]; | |
| 382 | - return uid; | |
| 383 | - } else { | |
| 384 | - NSInteger time = [[NSDate date] timeIntervalSince1970]; | |
| 385 | - NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time]; | |
| 386 | - NSString *stamp = timeString; | |
| 387 | - stamp = [stamp stringByReplacingOccurrencesOfString:@"." withString:@""]; | |
| 388 | - NSString *idfv = [NSString generateTradeNO]; | |
| 389 | - uid = [NSString stringWithFormat:@"%@_%@", idfv, stamp]; | |
| 390 | - [defauts setObject:uid forKey:uidKey]; | |
| 391 | - [defauts synchronize]; | |
| 392 | - return uid; | |
| 393 | - } | |
| 394 | -} | |
| 395 | -//产生随机字符串 | |
| 396 | -+ (NSString *)generateTradeNO | |
| 397 | -{ | |
| 398 | - static int kNumber = 30; | |
| 399 | - | |
| 400 | - NSString *sourceStr = @"0123456789ABCDEFGHIJKLMNOPQRST"; | |
| 401 | - NSMutableString *resultStr = [[NSMutableString alloc] init]; | |
| 402 | - for (int i = 0; i < kNumber; i++) | |
| 403 | - { | |
| 404 | - unsigned index = rand() % [sourceStr length]; | |
| 405 | - NSString *oneStr = [sourceStr substringWithRange:NSMakeRange(index, 1)]; | |
| 406 | - [resultStr appendString:oneStr]; | |
| 407 | - } | |
| 408 | - return resultStr; | |
| 409 | -} | |
| 376 | + | |
| 410 | 377 | @end | ... | ... |