Permalink
Browse files

Some refactorings in JSON generator.

  • Loading branch information...
1 parent 80572de commit 4504458f4fdc986a21f7be8352b801be16b8b9e3 @nicktoumpelis nicktoumpelis committed Dec 22, 2011
Showing with 73 additions and 22 deletions.
  1. +4 −2 BugSense-iOS.xcodeproj/project.pbxproj
  2. +69 −20 BugSense-iOS/BugSenseJSONGenerator.m
@@ -643,7 +643,7 @@
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = NO;
COPY_PHASE_STRIP = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
- DYLIB_CURRENT_VERSION = 1;
+ DYLIB_CURRENT_VERSION = 1.4;
FRAMEWORK_VERSION = A;
GCC_CW_ASM_SYNTAX = NO;
GCC_C_LANGUAGE_STANDARD = c99;
@@ -698,6 +698,8 @@
armv7,
);
COPY_PHASE_STRIP = NO;
+ DYLIB_COMPATIBILITY_VERSION = 1;
+ DYLIB_CURRENT_VERSION = 1.4;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_VERSION = "";
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
@@ -729,7 +731,7 @@
COPY_PHASE_STRIP = NO;
DSTROOT = /tmp/BugSense_iOS_Static_Library.dst;
DYLIB_COMPATIBILITY_VERSION = 1;
- DYLIB_CURRENT_VERSION = 1;
+ DYLIB_CURRENT_VERSION = 1.4;
GCC_CW_ASM_SYNTAX = NO;
GCC_C_LANGUAGE_STANDARD = c99;
GCC_ENABLE_CPP_EXCEPTIONS = NO;
@@ -43,14 +43,68 @@
#import "BugSenseJSONGenerator.h"
+#define kNoAddressStatus @"Could not be found."
+#define kAppNameNotFoundStatus @"App name not found."
#define kGeneratingJSONDataMsg @"BugSense --> Generating JSON data from crash report..."
#define kJSONErrorMsg @"BugSense --> Something unusual happened during the generation of JSON data!"
+#define kBugSenseFrameworkVersion @"1.0 (rev4)"
+#define kBugSensePlatform @"iOS"
+
@implementation BugSenseJSONGenerator
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-+ (NSString *) currentIPAddress {
- NSString *address = @"Could not be found";
++ (NSString *) frameworkVersion {
+ return kBugSenseFrameworkVersion;
+}
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
++ (NSString *) frameworkPlatform {
+ return kBugSensePlatform;
+}
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
++ (NSString *) applicationNameForReport:(PLCrashReport *)report {
+ NSArray *identifierComponents = [report.applicationInfo.applicationIdentifier componentsSeparatedByString:@"."];
+ if (identifierComponents && identifierComponents.count > 0) {
+ return [identifierComponents lastObject];
+ } else {
+ return kAppNameNotFoundStatus;
+ }
+}
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
++ (NSString *) applicationBuildNumberForReport:(PLCrashReport *)report {
+ CFBundleRef bundle = CFBundleGetBundleWithIdentifier((CFStringRef)report.applicationInfo.applicationIdentifier);
+ CFDictionaryRef bundleInfoDict = CFBundleGetInfoDictionary(bundle);
+ CFStringRef buildNumber;
+
+ // If we succeeded, look for our property.
+ if (bundleInfoDict != NULL) {
+ buildNumber = CFDictionaryGetValue(bundleInfoDict, CFSTR("CFBundleShortVersionString"));
+ if (buildNumber) {
+ return (NSString *)buildNumber;
+ } else {
+ return @"";
+ }
+ } else {
+ return @"";
+ }
+}
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
++ (NSString *) applicationVersionNumberForReport:(PLCrashReport *)report {
+ return report.applicationInfo.applicationVersion;
+}
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
++ (NSString *) IPAddress {
+ NSString *address = kNoAddressStatus;
struct ifaddrs *interfaces = NULL;
struct ifaddrs *temp_addr = NULL;
@@ -195,32 +249,27 @@ + (NSData *) JSONDataFromCrashReport:(PLCrashReport *)report userDictionary:(NSD
// --application_environment
NSMutableDictionary *application_environment = [[[NSMutableDictionary alloc] init] autorelease];
+ // ----bugsense_version
+ [application_environment setObject:[self frameworkVersion] forKey:@"version"];
+
+ // ----bugsense_name
+ [application_environment setObject:[self frameworkPlatform] forKey:@"name"];
+
// ----appname
- NSArray *identifierComponents = [report.applicationInfo.applicationIdentifier componentsSeparatedByString:@"."];
- if (identifierComponents && identifierComponents.count > 0) {
- [application_environment setObject:[identifierComponents lastObject] forKey:@"appname"];
- }
+ [application_environment setObject:[self applicationNameForReport:report] forKey:@"appname"];
// ----appver
- CFBundleRef bundle = CFBundleGetBundleWithIdentifier((CFStringRef)report.applicationInfo.applicationIdentifier);
- CFDictionaryRef bundleInfoDict = CFBundleGetInfoDictionary(bundle);
- CFStringRef buildNumber;
-
- // If we succeeded, look for our property.
- if (bundleInfoDict != NULL) {
- buildNumber = CFDictionaryGetValue(bundleInfoDict, CFSTR("CFBundleShortVersionString"));
- if (buildNumber) {
- [application_environment setObject:(NSString *)buildNumber forKey:@"appver"];
- }
- }
+ [application_environment setObject:[self applicationNameForReport:report] forKey:@"appver"];
// ----internal_version
- [application_environment setObject:report.applicationInfo.applicationVersion forKey:@"internal_version"];
+ [application_environment setObject:[self applicationVersionNumberForReport:report] forKey:@"internal_version"];
// ----gps_on
[application_environment setObject:[NSNumber numberWithBool:[CLLocationManager locationServicesEnabled]]
forKey:@"gps_on"];
-
+
+ CFBundleRef bundle = CFBundleGetBundleWithIdentifier((CFStringRef)report.applicationInfo.applicationIdentifier);
+ CFDictionaryRef bundleInfoDict = CFBundleGetInfoDictionary(bundle);
if (bundleInfoDict != NULL) {
NSMutableString *languages = [[[NSMutableString alloc] init] autorelease];
CFStringRef baseLanguage = CFDictionaryGetValue(bundleInfoDict, kCFBundleDevelopmentRegionKey);
@@ -396,7 +445,7 @@ + (NSData *) JSONDataFromCrashReport:(PLCrashReport *)report userDictionary:(NSD
NSMutableDictionary *request = [[[NSMutableDictionary alloc] init] autorelease];
// ----remote_ip
- [request setObject:[self currentIPAddress] forKey:@"remote_ip"];
+ [request setObject:[self IPAddress] forKey:@"remote_ip"];
if (userDictionary) {
[request setObject:userDictionary forKey:@"custom_data"];
}

0 comments on commit 4504458

Please sign in to comment.