Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 15 additions & 58 deletions KISSMetricsAPI.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// KISSMetricsAPI
//
// Created by Einar Vollset on 9/15/11.
// Updated to ARC 3/4/14
// Copyright 2011 KISSMetrics. All rights reserved.
//

Expand Down Expand Up @@ -77,19 +78,20 @@ @implementation KISSMetricsAPI
#pragma mark -
#pragma mark Singleton methods

+ (KISSMetricsAPI *) sharedAPIWithKey:(NSString *)apiKey


+ (KISSMetricsAPI *)sharedAPIWithKey:(NSString *)apiKey
{
@synchronized(self)
{
if (sharedAPI == nil) {
sharedAPI = [[KISSMetricsAPI alloc] init];
[sharedAPI initializeAPIWithKey:apiKey];
}

}
return sharedAPI;
static KISSMetricsAPI *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[KISSMetricsAPI alloc] init];
[sharedAPI initializeAPIWithKey:apiKey];
});
return sharedInstance;
}


+ (KISSMetricsAPI *) sharedAPI
{
@synchronized(self)
Expand Down Expand Up @@ -191,48 +193,6 @@ - (void) initializeAPIWithKey:(NSString *)apiKey
[self applicationWillEnterForeground:nil];
}

+ (id)allocWithZone:(NSZone *)zone
{
@synchronized(self) {
if (sharedAPI == nil)
{
sharedAPI = [super allocWithZone:zone];
return sharedAPI; // assignment and return on first allocation
}
}
return nil; // on subsequent allocation attempts return nil
}

- (id)copyWithZone:(NSZone *)zone
{
return self;
}

- (id)retain {
return self;
}

- (NSUInteger)retainCount {
return UINT_MAX; // denotes an object that cannot be released
}

- (oneway void)release {
//do nothing
}

- (id)autorelease {
return self;
}


- (id)init
{
self = [super init];
if (self) {
}

return self;
}


#pragma mark -
Expand Down Expand Up @@ -323,7 +283,6 @@ - (void) send

self.existingConnection = [NSURLConnection connectionWithRequest:request delegate:self];
[self.existingConnection start];
[request release];

// If called from a background thread
if(![NSThread isMainThread]){
Expand Down Expand Up @@ -398,10 +357,8 @@ - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)err
if ([self.sendQueue count] > 1)
{
NSString *failedURL = [self.sendQueue objectAtIndex:0];
[failedURL retain];
[self.sendQueue removeObjectAtIndex:0];
[self.sendQueue addObject:failedURL];
[failedURL release];
}
[self archiveData];

Expand Down Expand Up @@ -554,8 +511,8 @@ - (NSString *)urlizeProps:(NSDictionary *)props
//the NSString method doesn't work right, so..
- (NSString *)urlEncode:(NSString *)prior
{
NSString * after = (NSString *)CFURLCreateStringByAddingPercentEscapes( NULL,(CFStringRef)prior, NULL,(CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8 );
return [after autorelease];
NSString * after = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes( NULL,(CFStringRef)prior, NULL,(CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8 ));
return after;

}

Expand Down Expand Up @@ -702,7 +659,7 @@ - (void)clearIdentity
CFUUIDRef theUUID = CFUUIDCreate(NULL);
CFStringRef string = CFUUIDCreateString(NULL, theUUID);
CFRelease(theUUID);
self.lastIdentity = [(NSString *)string autorelease];
self.lastIdentity = (NSString *)CFBridgingRelease(string);
if (![NSKeyedArchiver archiveRootObject:self.lastIdentity toFile:IDENTITY_PATH])
{
InfoLog(@"KISSMetricsAPI: WARNING - Unable to archive identity!!!");
Expand Down