Thursday, March 15, 2012

EXC_BAD_ACCESS on iPhone

how to debug EXC_BAD_ACCESS on iPhone

http://www.codza.com/how-to-debug-exc_bad_access-on-iphone


If you set the NSZombieEnabled environment variable, the Objective C runtime will leave a dummy object behind for every deallocated object. When the zombie object is called, execution stops and you can see the message that was sent to the object and the call stack that tells you where the message came from (it doesn’t tell you where you over released the object, but knowing where the object is called from should get you pretty close to the problem.)
To set this variable, go to the info panel of the executable in xcode, and create a newenvironment variable in the arguments tab by clicking the plus sign in the lower left corner of the window. Name the variable NSZombieEnabled, type YES for the value and make sure that the checkbox is selected.

set NSZombieEnabled variable


Tuesday, February 14, 2012

Renaming Project in XCode 4


Renaming Project in XCode 4 :  
Some are having trouble figuring out how to rename projects in Xcode 4. As it happens, Apple’s made things quite easy. It renames the project and the product names of any targets sharing the project’s nameand any strings it finds in your nib/xib files. In theory, that is.
Here’s how:
  1. Open the project in Xcode 4.
  2. Click the project itself in the Project Navigator.
  3. Open the Utility pane (the right-most button in the View button panel in the right side of the toolbar).
  4. Select the File Inspector utility pane if it’s not already.
  5. Under the Identity group, set the Project Name field to whatever you like and press return.
  6. You’ll be asked which items to rename (including any targets or strings in nib/xib files sharing the same name as the project).
  7. Cherry pick which ones you want to rename (probably all of them) by unchecking those you don’t, then click Rename.
  8. You may be asked to take a snapshot of the project. My advice? Do it. Xcode 4 still has bugs and crashed on me the first time I tried this, resulting in a screwed up project. Click Enable to enable snapshots if asked.
  9. Assuming there are no errors, all checked items will have a green checkmark next to them and the rename sheet’s button will turn to Ok. Click it and you’re done.

Friday, December 30, 2011

iPad Launch Image Orientations


iPad Launch Image Orientations
To deal with various orientation options, a new naming convention has been created for iPad launch images. The screen size of the iPad is 768×1024, notice in the dimensions that follow the height takes into account a 20 pixel status bar.
Filename Dimensions
Default-Portrait.png * 768w x 1004h
Default-PortraitUpsideDown.png 768w x 1004h
Default-Landscape.png ** 1024w x 748h
Default-LandscapeLeft.png 1024w x 748h
Default-LandscapeRight.png 1024w x 748h
Default.png Not recommended
  • If you have not specified a Default-PortraitUpsideDown.png file, this file will take precedence.
** If you have not specified a Default-LandscapeLet.png or Default-LandscapeRight.png image file, this file will take precedence.

Tuesday, August 23, 2011

Divide value in three string


double distRemain = distInMeter;
originalDistRemain = distInMeter;
if(distRemain >0 && distRemain <10){
lblDistance.text = @"0";
lblDistance1.text = @"0";
int lastdigit = distRemain/1;
lblDistance2.text = [NSString stringWithFormat:@"%d",lastdigit];
 
}
else if(distRemain >=10 && distRemain < 100){
lblDistance.text = @"0";
int lasttwo = distRemain/10;
lblDistance1.text = [NSString stringWithFormat:@"%d",lasttwo];
distRemain = distRemain -(lasttwo *10);
int lastdigit = distRemain/1;
lblDistance2.text = [NSString stringWithFormat:@"%d",lastdigit];
}
else if(distRemain >=100 && distRemain < 1000){
int firstDigit = distRemain/100;
lblDistance.text = [NSString stringWithFormat:@"%d",firstDigit];
distRemain = distRemain - (firstDigit *100);
int lasttwo = distRemain/10;
lblDistance1.text = [NSString stringWithFormat:@"%d",lasttwo];
distRemain = distRemain -(lasttwo *10);
int lastdigit = distRemain/1;
lblDistance2.text = [NSString stringWithFormat:@"%d",lastdigit];
}

Monday, July 18, 2011

Void Pinter Meaning

Void Pinter Meaning :
void * p; 
The name of the blog comes from the world of software development. In the C, C++, and C# programming languages (and perhaps others), a void pointer is a variable containing an address in memory. The above line of code declares a void pointer named "p" that has not yet been set to an address. What is stored at the address is left unspecified and usually the void pointer is converted to be a pointer to a specific type (cast) before it is used. This construct gives the developer quite a bit of power, but as Uncle Ben said, "with great power, comes great responsibility". The developer can very easily shoot themselves in the foot with a void pointer, but when used carefully and in the right circumstances, one can accomplish wonderful things.

Thursday, July 7, 2011

PDF File attached in Email Composer in iPhone .

This piece of code also shows you how to attach pdfs as well.



UIButton *emailPdfButton=[[UIButton alloc]initWithFrame:CGRectMake(10, 10, 100, 40)];
[emailPdfButton setBackgroundColor:[UIColor greenColor]];
[emailPdfButton addTarget:self action:@selector(emailPdf:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:emailPdfButton];



-(IBAction)emailPdf:(id)sender{
    
    //find if email exists
    Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
    if (mailClass != nil)
    {        
        //find atleast one email account is set up
        if([MFMailComposeViewController canSendMail])
        {
            MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
[controller setMessageBody:nil isHTML:YES];
[controller setSubject:@"Subject."];
[controller setMessageBody:@"Body Of Email." isHTML:NO];
[controller setToRecipients:[NSArray arrayWithObjects:nil,nil]];
[controller addAttachmentData:[NSData dataWithContentsOfFile:[self GetPdfFilePath]]mimeType:@"application/pdf" fileName:@"file.pdf"];
controller.navigationBar.tintColor = [UIColor grayColor];
[controller setMailComposeDelegate:self];
[self presentModalViewController:controller animated:YES];
[controller release];
        
        }
        else
        {
            //display the alert that set up an email account
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Please set up your email account on device." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alertView show];
            [alertView release];
        }
    }
    else
    {
        //display the alert that email account not available
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"No valid email account available on device." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
        [alertView release];
    
    }
    
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
    
    
    
    NSString *message = @"";
    switch (result) {
         
        case MFMailComposeResultCancelled:
            message = @"Email Canceled";
            break;
        case MFMailComposeResultSaved:
            message = @"Email Saved";
            break;
        case MFMailComposeResultSent:
            message = @"Email Sent";
            break;
        case MFMailComposeResultFailed:
            message = @"Email Failed";
            break;
        default:
            message = @"Email Not Sent";
            break;

            
    }
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:message delegate:nilcancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
    [alertView release];
    [controller dismissModalViewControllerAnimated:YES];
}

Special Thanks for Mobile and Social NEtwork Technology.
Dinesh Sharma

Tuesday, July 5, 2011

iPhone iPad : check the current device and set the nib manually.

ActiveJobDetail *objActiveDetail;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200    
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
objActiveDetail = [[ActiveJobDetail alloc]initWithNibName:@"ActiveJobDetail-iPad" bundle:nil];
}
else 
#endif
{
objActiveDetail = [[ActiveJobDetail alloc]initWithNibName:@"ActiveJobDetail" bundle:nil];
}


//ActiveJobDetail *objActiveDetail = [[ActiveJobDetail alloc]initWithNibName:@"ActiveJobDetail" bundle:nil];
[self.navigationController pushViewController:objActiveDetail animated:YES];
[objActiveDetail release];