Sunday, October 16, 2011

Crash Reporter for iOS


Hi friends,
Today I google for find out easiest way to get information about crashes, when they occur in iOS application. Apple provides a mechanism for it: iOS records crash logs on device, when you sync it with iTunes the logs are copied to the user's computer. This make lots of work for user, So I start to find out its alternative.

At end I am able to found out a alternative of it. PLCrashReporter is "Plausible CrashReporter" is open source library develop Landon J Fuller. "It not just only creates a crash logs for you, But also makes it easy to tell the user about it the next time they start the application, and ask them if they'd like to email or upload  the report back to developer"

Its working video



To integrate PLCrashReporter you have to follow the following steps.

  1. Download the PLCrashReporter source release.
  2. Navigate to the CrashReporter-iPhoneSimulator Target. Under the Build Settings: a) set "Perform Single-Object Prelink" to "No", b) set "Mach-O Type" to "Static Library".
  3. Select CrashReport-iPhoneSimulator : [IOS simulation (ie iPhone 4.3 Simulator)] and click build.
  4. Navigate to your build directory for the PLCrashReporter. For me, it was /Users/username/Library/Developer/Xcode/DerivedData/CrashReporter-(random characters)/Build/Products/Debug-iphonesimulator.
  5.  Copy the libCrashReporter-iphonesimulator.a from the build directory in step 4 to the iphone application project directory you want to add the crash reporter to.
  6. Open the your iphone application project in xcode.
  7. Download the PLCrashReporter binary release and extract the framework to a local directory.
  8. Add the CrashReporter framework to your project.
  9. Following the same procedure as step 9, add the libCrashReporter-iphonesimulator.a static library to the "Link Binary with Libraries" section of the build phases. No *.framework directory is needed when adding a static library.
  10. 10.  Review the "Link Binary with Libraries" in the Target. Make sure the libCrashReporter-iphonesimulator.a is listed above the CrashReporter framework. You can drag and drop to reorder.
Coding part.
// from UIApplicationDelegate protocol
- (void) applicationDidFinishLaunching: (UIApplication *) application {
    PLCrashReporter *crashReporter = [PLCrashReporter sharedReporter];
    NSError *error;

    /* Check if we previously crashed */
    if ([crashReporter hasPendingCrashReport])
        [self handleCrashReport];

    /* Enable the Crash Reporter */
    if (![crashReporter enableCrashReporterAndReturnError: &error])
        NSLog(@"Warning: Could not enable crash reporter: %@", error);
}

/**
 * Called to handle a pending crash report.
 */
- (void) handleCrashReport {
    PLCrashReporter *crashReporter = [PLCrashReporter sharedReporter];
    NSData *crashData;
    NSError *error;

    /* Try loading the crash report */
    crashData = [crashReporter loadPendingCrashReportDataAndReturnError: &error];
    if (crashData == nil) {
        NSLog(@"Could not load crash report: %@", error);
        goto finish;
    }

    /* We could send the report from here, but we'll just print out
     * some debugging info instead */
    PLCrashReport *report = [[[PLCrashReport alloc] initWithData: crashData error: &error] autorelease];
    if (report == nil) {
        NSLog(@"Could not parse crash report");
        goto finish;
    }

    NSLog(@"Crashed on %@", report.systemInfo.timestamp);
    NSLog(@"Crashed with signal %@ (code %@, address=0x%" PRIx64 ")", report.signalInfo.name,
          report.signalInfo.code, report.signalInfo.address);

    /* Purge the report */
finish:
    [crashReporter purgePendingCrashReport];
    return;
}
Sample Code CrashReportHandling

Reference :



Tuesday, May 10, 2011

How to Make Custom Folder Icon in MAC

Hi 
I am sharing my first simple video tutorial






Tuesday, May 3, 2011

Email Validation in Objective C

-(BOOL)emailValidation:(NSString *)email {
    BOOL result;
    //checking email validation
    NSString *emailRegEx = @"[A-Z0-9a-z._-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegEx];
    //Valid email address
    if ([emailTest evaluateWithObject:email] == YES){
        NSLog(@"Valid email address");
        result=NO;
    }else{
        NSLog(@"Invalid email address");
        result=YES;
    }
    return result;
}

MD5 in Objective C

Just Import  CommonCrypto/CommonDigest.h and following method returns md5 string.

 #import <CommonCrypto/CommonDigest.h>

- (NSString *)convertIntoMD5:(NSString *) string{
    const char *cStr = [string UTF8String];
    unsigned char digest[16];

    CC_MD5( cStr, strlen(cStr), digest ); // This is the md5 call
   
    NSMutableString *resultString = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
   
    for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
        [resultString appendFormat:@"%02x", digest[i]];
    return  resultString;
}