diff --git a/DeviceInfo.m b/DeviceInfo.m index eb66a05e..5cd2fc33 100644 --- a/DeviceInfo.m +++ b/DeviceInfo.m @@ -12,7 +12,9 @@ @interface DeviceInfo () @end -@implementation DeviceInfo +@implementation DeviceInfo { + NSObject* networkInfo; +} @synthesize versionName = _versionName; @synthesize buildVersionRelease = _buildVersionRelease; @@ -25,6 +27,7 @@ @implementation DeviceInfo + -(id) init { self = [super init]; return self; @@ -61,17 +64,16 @@ -(NSString*) phoneCarrier { SEL subscriberCellularProvider = NSSelectorFromString(@"subscriberCellularProvider"); SEL carrierName = NSSelectorFromString(@"carrierName"); if (CTTelephonyNetworkInfo && subscriberCellularProvider && carrierName) { - NSObject *info = [[NSClassFromString(@"CTTelephonyNetworkInfo") alloc] init]; - id (*imp1)(id, SEL) = (id (*)(id, SEL))[info methodForSelector:subscriberCellularProvider]; - id carrier; + networkInfo = [[NSClassFromString(@"CTTelephonyNetworkInfo") alloc] init]; + id carrier = nil; + id (*imp1)(id, SEL) = (id (*)(id, SEL))[networkInfo methodForSelector:subscriberCellularProvider]; if (imp1) { - carrier = imp1(info, subscriberCellularProvider); + carrier = imp1(networkInfo, subscriberCellularProvider); } NSString* (*imp2)(id, SEL) = (NSString* (*)(id, SEL))[carrier methodForSelector:carrierName]; if (imp2) { _phoneCarrier = imp2(carrier, carrierName); } - SAFE_ARC_RELEASE(info); } } return _phoneCarrier; @@ -125,22 +127,20 @@ + (NSString*)getAdvertiserID:(int) maxAttempts Class ASIdentifierManager = NSClassFromString(@"ASIdentifierManager"); SEL sharedManager = NSSelectorFromString(@"sharedManager"); SEL advertisingIdentifier = NSSelectorFromString(@"advertisingIdentifier"); - SEL UUIDString = NSSelectorFromString(@"UUIDString"); - if (ASIdentifierManager && sharedManager && advertisingIdentifier && UUIDString) { + if (ASIdentifierManager && sharedManager && advertisingIdentifier) { id (*imp1)(id, SEL) = (id (*)(id, SEL))[ASIdentifierManager methodForSelector:sharedManager]; - id manager; - id adid; - NSString* identifier; + id manager = nil; + NSUUID *adid = nil; + NSString *identifier = nil; if (imp1) { manager = imp1(ASIdentifierManager, sharedManager); } - id (*imp2)(id, SEL) = (id (*)(id, SEL))[manager methodForSelector:advertisingIdentifier]; + NSUUID* (*imp2)(id, SEL) = (NSUUID* (*)(id, SEL))[manager methodForSelector:advertisingIdentifier]; if (imp2) { adid = imp2(manager, advertisingIdentifier); } - NSString* (*imp3)(id, SEL) = (NSString* (*)(id, SEL))[adid methodForSelector:UUIDString]; - if (imp3) { - identifier = imp3(adid, UUIDString); + if (adid) { + identifier = [adid UUIDString]; } if (identifier == nil && maxAttempts > 0) { // Try again every 5 seconds @@ -181,7 +181,7 @@ - (NSString*)generateUUID return result; } -+ (NSString *)getPlatformString ++ (NSString*)getPlatformString { size_t size; sysctlbyname("hw.machine", NULL, &size, NULL, 0); @@ -192,7 +192,7 @@ + (NSString *)getPlatformString return platform; } -+ (NSString *)getPhoneModel{ ++ (NSString*)getPhoneModel{ NSString *platform = [self getPlatformString]; if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 1"; if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";