Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)_performSendingCrashReports {
- NSMutableDictionary *approvedCrashReports = [NSMutableDictionary dictionaryWithDictionary:[[NSUserDefaults standardUserDefaults] dictionaryForKey: kApprovedCrashReports]];
- NSError *error = NULL;
- NSString *userid = @"";
- NSString *contact = @"";
- NSString *description = @"";
- if (self.delegate != nil && [self.delegate respondsToSelector:@selector(crashReportUserID)]) {
- userid = [self.delegate crashReportUserID] ?: @"";
- }
- if (self.delegate != nil && [self.delegate respondsToSelector:@selector(crashReportContact)]) {
- contact = [self.delegate crashReportContact] ?: @"";
- }
- if (self.delegate != nil && [self.delegate respondsToSelector:@selector(crashReportDescription)]) {
- description = [self.delegate crashReportDescription] ?: @"";
- }
- NSMutableString *crashes = nil;
- _crashIdenticalCurrentVersion = NO;
- for (NSUInteger i=0; i < [_crashFiles count]; i++) {
- NSString *filename = [_crashesDir stringByAppendingPathComponent:[_crashFiles objectAtIndex:i]];
- NSData *crashData = [NSData dataWithContentsOfFile:filename];
- if ([crashData length] > 0) {
- PLCrashReport *report = [[[PLCrashReport alloc] initWithData:crashData error:&error] autorelease];
- if (report == nil) {
- NSLog(@"Could not parse crash report");
- continue;
- }
- NSString *crashLogString = [PLCrashReportTextFormatter stringValueForCrashReport:report withTextFormat:PLCrashReportTextFormatiOS];
- if ([report.applicationInfo.applicationVersion compare:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]] == NSOrderedSame) {
- _crashIdenticalCurrentVersion = YES;
- }
- if (crashes == nil) {
- crashes = [NSMutableString string];
- }
- [crashes appendFormat:@"<crash><applicationname>%s</applicationname><bundleidentifier>%@</bundleidentifier><systemversion>%@</systemversion><platform>%@</platform><senderversion>%@</senderversion><version>%@</version><log><![CDATA[%@]]></log><userid>%@</userid><contact>%@</contact><description><![CDATA[%@]]></description></crash>",
- [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleExecutable"] UTF8String],
- report.applicationInfo.applicationIdentifier,
- report.systemInfo.operatingSystemVersion,
- [self _getDevicePlatform],
- [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"],
- report.applicationInfo.applicationVersion,
- [crashLogString stringByReplacingOccurrencesOfString:@"]]>" withString:@"]]" @"]]><![CDATA[" @">" options:NSLiteralSearch range:NSMakeRange(0,crashLogString.length)],
- userid,
- contact,
- [description stringByReplacingOccurrencesOfString:@"]]>" withString:@"]]" @"]]><![CDATA[" @">" options:NSLiteralSearch range:NSMakeRange(0,description.length)]];
- // store this crash report as user approved, so if it fails it will retry automatically
- [approvedCrashReports setObject:[NSNumber numberWithBool:YES] forKey:[_crashFiles objectAtIndex:i]];
- } else {
- // we cannot do anything with this report, so delete it
- [self.fileManager removeItemAtPath:filename error:&error];
- }
- }
- [[NSUserDefaults standardUserDefaults] setObject:approvedCrashReports forKey:kApprovedCrashReports];
- [[NSUserDefaults standardUserDefaults] synchronize];
- if (crashes != nil) {
- BWQuincyLog(@"Sending crash reports:\n%@", crashes);
- [self _postXML:[NSString stringWithFormat:@"<crashes>%@</crashes>", crashes]
- toURL:[NSURL URLWithString:self.submissionURL]];
- }
- }
- [7/26/55 BE 5:22:19 PM] Aemgtz:
- - (void)_postXML:(NSString*)xml toURL:(NSURL*)url {
- NSMutableURLRequest *request = nil;
- NSString *boundary = @"----FOO";
- if (self.appIdentifier) {
- request = [NSMutableURLRequest requestWithURL:
- [NSURL URLWithString:[NSString stringWithFormat:@"%@api/2/apps/%@/crashes?sdk=%@&sdk_version=%@",
- self.submissionURL,
- [self.appIdentifier stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
- SDK_NAME,
- SDK_VERSION
- ]
- ]];
- } else {
- request = [NSMutableURLRequest requestWithURL:url];
- }
- [request setCachePolicy: NSURLRequestReloadIgnoringLocalCacheData];
- [request setValue:@"Quincy/iOS" forHTTPHeaderField:@"User-Agent"];
- [request setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
- [request setTimeoutInterval: 15];
- [request setHTTPMethod:@"POST"];
- NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
- [request setValue:contentType forHTTPHeaderField:@"Content-type"];
- NSMutableData *postBody = [NSMutableData data];
- [postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
- if (self.appIdentifier) {
- [postBody appendData:[@"Content-Disposition: form-data; name=\"xml\"; filename=\"crash.xml\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
- [postBody appendData:[[NSString stringWithFormat:@"Content-Type: text/xml\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
- } else {
- [postBody appendData:[@"Content-Disposition: form-data; name=\"xmlstring\"\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
- }
- [postBody appendData:[xml dataUsingEncoding:NSUTF8StringEncoding]];
- [postBody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
- [request setHTTPBody:postBody];
- _serverResult = CrashReportStatusUnknown;
- _statusCode = 200;
- //Release when done in the delegate method
- _responseData = [[NSMutableData alloc] init];
- if (self.delegate != nil && [self.delegate respondsToSelector:@selector(connectionOpened)]) {
- [self.delegate connectionOpened];
- }
- _urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
- if (!_urlConnection) {
- BWQuincyLog(@"Sending crash reports could not start!");
- _sendingInProgress = NO;
- } else {
- BWQuincyLog(@"Sending crash reports started.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement