Permalink
Browse files

Release v12.07

* Added _app_version to metrics
* OpenUDID is updated
* Fixed character escape issues
  • Loading branch information...
1 parent 93fc435 commit 56345db6b2d0db813769dd0248dfece166738821 Onur Alp Soner committed Jul 29, 2012
Showing with 77 additions and 8 deletions.
  1. +62 −2 Countly.m
  2. +15 −6 Countly_OpenUDID.m
View
@@ -23,6 +23,59 @@
#include <sys/types.h>
#include <sys/sysctl.h>
+
+/// Utilities for encoding and decoding URL arguments.
+/// This code is from the project google-toolbox-for-mac
+@interface NSString (GTMNSStringURLArgumentsAdditions)
+
+/// Returns a string that is escaped properly to be a URL argument.
+//
+/// This differs from stringByAddingPercentEscapesUsingEncoding: in that it
+/// will escape all the reserved characters (per RFC 3986
+/// <http://www.ietf.org/rfc/rfc3986.txt>) which
+/// stringByAddingPercentEscapesUsingEncoding would leave.
+///
+/// This will also escape '%', so this should not be used on a string that has
+/// already been escaped unless double-escaping is the desired result.
+- (NSString*)gtm_stringByEscapingForURLArgument;
+
+/// Returns the unescaped version of a URL argument
+//
+/// This has the same behavior as stringByReplacingPercentEscapesUsingEncoding:,
+/// except that it will also convert '+' to space.
+- (NSString*)gtm_stringByUnescapingFromURLArgument;
+
+@end
+
+#define GTMNSMakeCollectable(cf) ((id)(cf))
+#define GTMCFAutorelease(cf) ([GTMNSMakeCollectable(cf) autorelease])
+
+@implementation NSString (GTMNSStringURLArgumentsAdditions)
+
+- (NSString*)gtm_stringByEscapingForURLArgument {
+ // Encode all the reserved characters, per RFC 3986
+ // (<http://www.ietf.org/rfc/rfc3986.txt>)
+ CFStringRef escaped =
+ CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
+ (CFStringRef)self,
+ NULL,
+ (CFStringRef)@"!*'();:@&=+$,/?%#[]",
+ kCFStringEncodingUTF8);
+ return GTMCFAutorelease(escaped);
+}
+
+- (NSString*)gtm_stringByUnescapingFromURLArgument {
+ NSMutableString *resultString = [NSMutableString stringWithString:self];
+ [resultString replaceOccurrencesOfString:@"+"
+ withString:@" "
+ options:NSLiteralSearch
+ range:NSMakeRange(0, [resultString length])];
+ return [resultString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+}
+
+@end
+
+
@interface DeviceInfo : NSObject
{
}
@@ -78,6 +131,11 @@ + (NSString *)locale
return [[NSLocale currentLocale] localeIdentifier];
}
++ (NSString *)appVersion
+{
+ return [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleVersionKey];
+}
+
+ (NSString *)metrics
{
NSString *result = @"{";
@@ -96,9 +154,11 @@ + (NSString *)metrics
result = [result stringByAppendingFormat:@",\"%@\":\"%@\"", @"_locale", [DeviceInfo locale]];
+ result = [result stringByAppendingFormat:@",\"%@\":\"%@\"", @"_app_version", [DeviceInfo appVersion]];
+
result = [result stringByAppendingString:@"}"];
- result = [result stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+ result = [result gtm_stringByEscapingForURLArgument];
return result;
}
@@ -330,7 +390,7 @@ - (void)dealloc
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillTerminateNotification object:nil];
- if(timer)
+ if (timer)
{
[timer invalidate];
timer = nil;
View
@@ -39,7 +39,7 @@
#if __has_feature(objc_arc)
#error This file uses the classic non-ARC retain/release model; hints below...
// to selectively compile this file as non-ARC, do as follows:
- // https://img.skitch.com/20120411-bcku69k1uw528cwh9frh5px8ya.png
+ // https://img.skitch.com/20120717-g3ag5h9a6ehkgpmpjiuen3qpwp.png
#endif
#import "Countly_OpenUDID.h"
@@ -121,21 +121,30 @@ + (NSString*) _generateFreshOpenUDID {
// _openUDID = [[UIDevice currentDevice] uniqueIdentifier];
// }
#endif
- // Next we try to use an alternative method which uses the host name, process ID, and a time stamp
- // We then hash it with md5 to get 32 bytes, and then add 4 extra random bytes
- // Collision is possible of course, but unlikely and suitable for most industry needs (e.g.. aggregate tracking)
+ // Next we generate a UUID.
+ // UUIDs (Universally Unique Identifiers), also known as GUIDs (Globally Unique Identifiers) or IIDs
+ // (Interface Identifiers), are 128-bit values guaranteed to be unique. A UUID is made unique over
+ // both space and time by combining a value unique to the computer on which it was generated—usually the
+ // Ethernet hardware address—and a value representing the number of 100-nanosecond intervals since
+ // October 15, 1582 at 00:00:00.
+ // We then hash this UUID with md5 to get 32 bytes, and then add 4 extra random bytes
+ // Collision is possible of course, but unlikely and suitable for most industry needs (e.g. aggregate tracking)
//
if (_openUDID==nil) {
+ CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
+ CFStringRef cfstring = CFUUIDCreateString(kCFAllocatorDefault, uuid);
+ const char *cStr = CFStringGetCStringPtr(cfstring,CFStringGetFastestEncoding(cfstring));
unsigned char result[16];
- const char *cStr = [[[NSProcessInfo processInfo] globallyUniqueString] UTF8String];
CC_MD5( cStr, strlen(cStr), result );
+ CFRelease(uuid);
+
_openUDID = [NSString stringWithFormat:
@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%08x",
result[0], result[1], result[2], result[3],
result[4], result[5], result[6], result[7],
result[8], result[9], result[10], result[11],
result[12], result[13], result[14], result[15],
- arc4random() % 4294967295];
+ (NSUInteger)(arc4random() % NSUIntegerMax)];
}
// Call to other developers in the Open Source community:

0 comments on commit 56345db

Please sign in to comment.