Created
January 21, 2014 07:42
-
-
Save blacklee/8535834 to your computer and use it in GitHub Desktop.
使用友盟统计分析提交时被拒的一种解决方案
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "MobClickOpenUDID+Swizzled.h" | |
#import <objc/message.h> | |
#import <JRSwizzle.h> // Swizzle 类方法,这样可以避免类去调用某些Apple可能不允许的方法,通过审核 | |
#import "YourDevice.h" // 你的设备相关类,用于生成自己的Device Unique ID | |
#import <RegExCategories.h> // 正则表达式 | |
#import <NSString+Ruby.h> // 字符串工具类 | |
static NSString * const kOpenUDIDKey = @"OpenUDID"; | |
static NSString * const kOpenUDIDSlotKey = @"OpenUDID_slot"; | |
static NSString * const kOpenUDIDAppUIDKey = @"OpenUDID_appUID"; | |
static NSString * const kOpenUDIDTSKey = @"OpenUDID_createdTS"; | |
static NSString * const kOpenUDIDOOTSKey = @"OpenUDID_optOutTS"; | |
static NSString * const kOpenUDIDDomain = @"org.OpenUDID"; | |
static NSString * const kOpenUDIDSlotPBPrefix = @"org.OpenUDID.slot."; | |
@implementation MobClickOpenUDID (Swizzled) | |
+ (id)_valueWithError:(__autoreleasing id *)arg1 { | |
NSString *openUDID = nil; | |
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | |
id localDict = [defaults objectForKey:@"OpenUDID"]; | |
if (localDict == nil) { | |
NSString *obj1 = [YourDevice myToken]; // 这个是自己的设备类,通常我们会给当前设备生成一个随机的唯一串,用这个来保证之前OpenUDID所保证的唯一性 | |
openUDID = [RX(@"\\W") replace:obj1 with:@""]; | |
while ([openUDID length] < 40) { | |
openUDID = [openUDID stringByAppendingString:@"0"]; | |
} | |
openUDID = [openUDID lowercaseString]; | |
localDict = [NSMutableDictionary dictionaryWithCapacity:4]; | |
[localDict setObject:openUDID forKey:kOpenUDIDKey]; | |
[localDict setObject:obj1 forKey:kOpenUDIDAppUIDKey]; | |
[localDict setObject:[NSDate date] forKey:kOpenUDIDTSKey]; | |
[localDict setObject:@"org.OpenUDID.slot.6" forKey:kOpenUDIDSlotKey]; | |
[defaults setObject:localDict forKey:kOpenUDIDKey]; | |
[defaults synchronize]; | |
} else { | |
openUDID = localDict[kOpenUDIDKey]; | |
} | |
return openUDID; | |
} | |
+ (void)load | |
{ | |
NSError *err = nil; | |
[self jr_swizzleClassMethod:@selector(valueWithError:) withClassMethod:@selector(_valueWithError:) error:&err]; | |
if (err) { | |
DLog(@"%@", err); | |
} | |
} | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface MobClickOpenUDID : NSObject | |
+ (id)valueWithError:(id *)arg1; | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment