Commit d5f7fd2fff5865a2e397c347a7923698d08a43b5
1 parent
8ab8e6ab
生成uuid随机字符串
Showing
3 changed files
with
37 additions
and
23 deletions
CNLiveScioLive/Pages/Login/Controller/CNLiveLoginViewController.m
| @@ -15,6 +15,7 @@ | @@ -15,6 +15,7 @@ | ||
| 15 | #import "ZXWUserModel.h" | 15 | #import "ZXWUserModel.h" |
| 16 | #import <AuthenticationServices/AuthenticationServices.h> | 16 | #import <AuthenticationServices/AuthenticationServices.h> |
| 17 | #import <CNLiveRequestBastKit/CNLiveNetworking.h> | 17 | #import <CNLiveRequestBastKit/CNLiveNetworking.h> |
| 18 | +#import "NSString+Validation.h" | ||
| 18 | 19 | ||
| 19 | @interface CNLiveLoginViewController ()<ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding> | 20 | @interface CNLiveLoginViewController ()<ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding> |
| 20 | @property (nonatomic, strong) CNLiveLoginInputView *account; | 21 | @property (nonatomic, strong) CNLiveLoginInputView *account; |
| @@ -471,7 +472,7 @@ | @@ -471,7 +472,7 @@ | ||
| 471 | [mDict setValue:@"i" forKey:@"plat"]; | 472 | [mDict setValue:@"i" forKey:@"plat"]; |
| 472 | [mDict setValue:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] forKey:@"ver"]; | 473 | [mDict setValue:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] forKey:@"ver"]; |
| 473 | [mDict setObject:CNLiveAppId forKey:@"appId"]; | 474 | [mDict setObject:CNLiveAppId forKey:@"appId"]; |
| 474 | - [mDict setValue:[self uuid] forKey:@"uuid"]; | 475 | + [mDict setValue:[NSString uuid] forKey:@"uuid"]; |
| 475 | 476 | ||
| 476 | [CNLiveNetworking setupDefaultParam:mDict]; | 477 | [CNLiveNetworking setupDefaultParam:mDict]; |
| 477 | [CNLiveNetworking setupShowResult:NO]; | 478 | [CNLiveNetworking setupShowResult:NO]; |
| @@ -480,26 +481,6 @@ | @@ -480,26 +481,6 @@ | ||
| 480 | [CNLiveNetworking setResponseSerializerType:CNLiveResponseSerializerJSON]; | 481 | [CNLiveNetworking setResponseSerializerType:CNLiveResponseSerializerJSON]; |
| 481 | 482 | ||
| 482 | } | 483 | } |
| 483 | -- (NSString *)uuid{ | ||
| 484 | - NSString *uid = @""; | ||
| 485 | - NSString *uidKey = @"kCNLiveUserDefaultsUIDKey"; | ||
| 486 | - NSUserDefaults *defauts = [NSUserDefaults standardUserDefaults]; | ||
| 487 | - if ([defauts objectForKey:uidKey]) { | ||
| 488 | - uid = [[defauts objectForKey:uidKey] copy]; | ||
| 489 | - return uid; | ||
| 490 | - } else { | ||
| 491 | - NSInteger time = [[NSDate date] timeIntervalSince1970]; | ||
| 492 | - NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time]; | ||
| 493 | - NSString *stamp = timeString; | ||
| 494 | - stamp = [stamp stringByReplacingOccurrencesOfString:@"." withString:@""]; | ||
| 495 | - NSString *idfv = [[[[UIDevice currentDevice] identifierForVendor] UUIDString] stringByReplacingOccurrencesOfString:@"-" withString:@""]; | ||
| 496 | - uid = [NSString stringWithFormat:@"%@_%@", idfv, stamp]; | ||
| 497 | - [defauts setObject:uid forKey:uidKey]; | ||
| 498 | - [defauts synchronize]; | ||
| 499 | - return uid; | ||
| 500 | - } | ||
| 501 | -} | ||
| 502 | - | ||
| 503 | - (UIStatusBarStyle)preferredStatusBarStyle { | 484 | - (UIStatusBarStyle)preferredStatusBarStyle { |
| 504 | return UIStatusBarStyleLightContent; | 485 | return UIStatusBarStyleLightContent; |
| 505 | } | 486 | } |
CNLiveScioLive/Pages/Tools/ValidationTool/NSString+Validation.h
| @@ -60,5 +60,5 @@ | @@ -60,5 +60,5 @@ | ||
| 60 | - (BOOL)isValidPassWordLegal; | 60 | - (BOOL)isValidPassWordLegal; |
| 61 | - (BOOL)isValidPasswordString; | 61 | - (BOOL)isValidPasswordString; |
| 62 | + (NSString *)numberSuitScanf:(NSString*)number; | 62 | + (NSString *)numberSuitScanf:(NSString*)number; |
| 63 | - | 63 | ++ (NSString *)uuid; |
| 64 | @end | 64 | @end |
CNLiveScioLive/Pages/Tools/ValidationTool/NSString+Validation.m
| @@ -373,5 +373,38 @@ | @@ -373,5 +373,38 @@ | ||
| 373 | 373 | ||
| 374 | 374 | ||
| 375 | } | 375 | } |
| 376 | - | 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 | +} | ||
| 377 | @end | 410 | @end |