Authored by 周蓉君

优化新旧设备判断逻辑。Review by 硬币。

@@ -69,6 +69,7 @@ static int const kOpenUDIDRedundancySlots = 100; @@ -69,6 +69,7 @@ static int const kOpenUDIDRedundancySlots = 100;
69 static NSString * const kYohoSecretInfo = @"com.yoho.buy.secretinfo"; 69 static NSString * const kYohoSecretInfo = @"com.yoho.buy.secretinfo";
70 static NSString * const kYohoBuyUdid = @"com.yoho.buy.udid"; 70 static NSString * const kYohoBuyUdid = @"com.yoho.buy.udid";
71 71
  72 +static BOOL isNew = YES;
72 static NSString * const kYohoDeviceInfo = @"com.yoho.buy.deviceinfo"; 73 static NSString * const kYohoDeviceInfo = @"com.yoho.buy.deviceinfo";
73 static NSString * const kYohoBuyUsedDevice = @"com.yoho.buy.useddevice"; 74 static NSString * const kYohoBuyUsedDevice = @"com.yoho.buy.useddevice";
74 75
@@ -397,12 +398,9 @@ static NSString * const kYohoBuyUsedDevice = @"com.yoho.buy.useddevice"; @@ -397,12 +398,9 @@ static NSString * const kYohoBuyUsedDevice = @"com.yoho.buy.useddevice";
397 398
398 + (void) setUsedDevice 399 + (void) setUsedDevice
399 { 400 {
400 - NSMutableDictionary *yohoinfoKVPairs = (NSMutableDictionary *)[YH_KeychainStore load:kYohoDeviceInfo];  
401 - if (yohoinfoKVPairs == nil) {  
402 - yohoinfoKVPairs = [NSMutableDictionary dictionary];  
403 - }  
404 -  
405 - if (![yohoinfoKVPairs[kYohoBuyUsedDevice] isEqualToString:@"Y"]) { 401 + if ([self isNewDevice]) {
  402 + isNew = NO;
  403 + NSMutableDictionary *yohoinfoKVPairs = [NSMutableDictionary dictionary];
406 [yohoinfoKVPairs setObject:@"Y" forKey:kYohoBuyUsedDevice]; 404 [yohoinfoKVPairs setObject:@"Y" forKey:kYohoBuyUsedDevice];
407 [YH_KeychainStore save:kYohoDeviceInfo data:yohoinfoKVPairs]; 405 [YH_KeychainStore save:kYohoDeviceInfo data:yohoinfoKVPairs];
408 } 406 }
@@ -410,18 +408,15 @@ static NSString * const kYohoBuyUsedDevice = @"com.yoho.buy.useddevice"; @@ -410,18 +408,15 @@ static NSString * const kYohoBuyUsedDevice = @"com.yoho.buy.useddevice";
410 408
411 + (BOOL) isNewDevice 409 + (BOOL) isNewDevice
412 { 410 {
413 - static BOOL isNew = YES;  
414 - if (isNew == NO) {  
415 - return NO;  
416 - } 411 + static dispatch_once_t onceToken;
  412 + dispatch_once(&onceToken, ^{
  413 + NSMutableDictionary *yohoinfoKVPairs = (NSMutableDictionary *)[YH_KeychainStore load:kYohoDeviceInfo];
  414 + if (yohoinfoKVPairs && yohoinfoKVPairs[kYohoBuyUsedDevice]) {
  415 + isNew = NO;
  416 + }
  417 + });
417 418
418 - NSMutableDictionary *yohoinfoKVPairs = (NSMutableDictionary *)[YH_KeychainStore load:kYohoDeviceInfo];  
419 - if (yohoinfoKVPairs == nil || yohoinfoKVPairs[kYohoBuyUsedDevice] == nil) {  
420 - return YES;  
421 - } else {  
422 - isNew = NO;  
423 - return NO;  
424 - } 419 + return isNew;
425 } 420 }
426 421
427 @end 422 @end