Skip to content

Instantly share code, notes, and snippets.

Created August 29, 2011 18:19
Show Gist options
  • Save betamike/1179006 to your computer and use it in GitHub Desktop.
Save betamike/1179006 to your computer and use it in GitHub Desktop.
NSString *logsPath = [[NSFileManager pathToDocumentsDirectory] stringByAppendingPathComponent:@".logs"];
NSArray *filenames = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:logsPath error:NULL];
if (filenames == nil)
NSMutableData *postData = [NSMutableData data];
[postData appendData:[@"[ \n" dataUsingEncoding:NSUTF8StringEncoding]];
for (NSString *filename in filenames)
NSFileHandle *file = [NSFileHandle fileHandleForReadingAtPath:[logsPath stringByAppendingPathComponent:filename]];
[postData appendData:[file readDataToEndOfFile]];
[file closeFile];
[postData appendData:[@"{} \n ]" dataUsingEncoding:NSUTF8StringEncoding]];
NSString *platformString = [[[UIDevice currentDevice] platformString] stringWithURLEncoding];
NSString *sdkString = [[NSString stringWithFormat:@"%@ %@", [[UIDevice currentDevice] systemName], [[UIDevice currentDevice] systemVersion]] stringWithURLEncoding];
NSString *appVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
User *user = [[GSUserManager sharedManager] currentUser];
NSString *carrierName = @"na";
if (NSClassFromString(@"CTTelephonyNetworkInfo"))
CTTelephonyNetworkInfo *netInfo = [[[CTTelephonyNetworkInfo alloc] init] autorelease];
CTCarrier *carrier = [netInfo subscriberCellularProvider];
carrierName = [carrier carrierName];
NSString *urlPath = [NSString stringWithFormat:@"",
[user userID], sdkString, platformString, appVersion, carrierName];
ASIHTTPRequest *req = [[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:urlPath]];
[req setDelegate:self];
[req setPostBody:postData];
[req startAsynchronous];
[loading setLoadingText:NSLocalizedString(@"Sending...", @"message shown while sending logs to GS")];
[loading setLoading:YES];
[loading fadeInWithDuration:0.5];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment