RSS

Monthly Archives: April 2012

How to send mail from iPhone Programatically

-(IBAction)showPicker:(id)sender {
// This sample can run on devices running iPhone OS 2.0 or later
// The MFMailComposeViewController class is only available in iPhone OS 3.0 or later.
// So, we must verify the existence of the above class and provide a workaround for devices running
// earlier versions of the iPhone OS.
// We display an email composition interface if MFMailComposeViewController exists and the device can send emails.
// We launch the Mail application on the device, otherwise.

Class mailClass = (NSClassFromString(@”MFMailComposeViewController”));
if (mailClass != nil)
{
// We must always check whether the current device is configured for sending emails
if ([mailClass canSendMail])
{
[self displayComposerSheet];
}
else
{
[self launchMailAppOnDevice];
}
}
else
{
[self launchMailAppOnDevice];
}
}

-(void)displayComposerSheet {
// Displays an email composition interface inside the application. Populates all the Mail fields.

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

[picker setSubject:@”Hello from California!”];

// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@”first@example.com”];
NSArray *ccRecipients = [NSArray arrayWithObjects:@”second@example.com”, @”third@example.com”, nil];
NSArray *bccRecipients = [NSArray arrayWithObject:@”fourth@example.com”];

[picker setToRecipients:toRecipients];
[picker setCcRecipients:ccRecipients];
[picker setBccRecipients:bccRecipients];

// Attach an image to the email
NSString *path = [[NSBundle mainBundle] pathForResource:@”rainy” ofType:@”png”];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@”image/png” fileName:@”rainy”];

// Fill out the email body text
NSString *emailBody = @”It is raining in sunny California!”;
[picker setMessageBody:emailBody isHTML:NO];

[self presentModalViewController:picker animated:YES];
[picker release];
}

– (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation.
message.hidden = NO;
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
message.text = @”Result: canceled”;
break;
case MFMailComposeResultSaved:
message.text = @”Result: saved”;
break;
case MFMailComposeResultSent:
message.text = @”Result: sent”;
break;
case MFMailComposeResultFailed:
message.text = @”Result: failed”;
break;
default:
message.text = @”Result: not sent”;
break;
}
[self dismissModalViewControllerAnimated:YES];
}

-(void)launchMailAppOnDevice {

// Launches the Mail application on the device.
NSString *recipients = @”mailto:first@example.com?cc=second@example.com,third@example.com&subject=Hello from California!”;
NSString *body = @”&body=It is raining in sunny California!”;

NSString *email = [NSString stringWithFormat:@”%@%@”, recipients, body];
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}

 
Leave a comment

Posted by on April 27, 2012 in Uncategorized

 

How to call webservice in background Through disptach queue

1 ) you have to import the following library file to class in which you want to create disptach_queue

#import

2 ) Then create object for dispatch_queue

dispatch_queue_t backgroundQueue;

3 ) Now just initialize queue where you want using this code

//1)Create backgrounnd queue
backgroundQueue= dispatch_queue_create(“jasoncall.backgroundqueue”, NULL);
//2)call asynchronously process through created dispatch queue
dispatch_async(backgroundQueue, ^(void){
[self GetClientInfoBackBroundCall];/// function name which you want to call in background
});

 
1 Comment

Posted by on April 26, 2012 in Uncategorized

 

Send SMS from iPhone Programatically

Sample code is at below link :
http://iphonedevelopertips.com/core-services/how-to-send-an-sms-progammatically.html

 
Leave a comment

Posted by on April 26, 2012 in Uncategorized

 

Mac trick to hide and show hidden folder…

1 ) if you want to show hidden folder in mac os then you have to write two commands in terminal one by one

First : defaults write com.apple.finder AppleShowAllFiles -bool true
Second : killall Finder

after run this two cmd in terminal you can see your hidden folder

2 ) Now if you want to hide this folder then following two commands you have to run in terminal

First : defaults write com.apple.finder AppleShowAllFiles -bool false
Second : killall Finder

 
Leave a comment

Posted by on April 23, 2012 in Uncategorized

 

UILongPressGestures

Q ) How to Add UILonggestures to UIButton ?
Ans :

you have to add this function into your class

– (void)longPressHandler:(UILongPressGestureRecognizer *)gestureRecognizer {
if(UIGestureRecognizerStateBegan == gestureRecognizer.state) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@”” message:@”Are you sure, you want to delete QR Code?” delegate:self cancelButtonTitle:@”Cancel” otherButtonTitles:@”Ok”,nil];
alert.tag = 1000;
[alert show];
[alert release];
}

}

And add gestures to uibutton this way

longpressGestureIDBadge = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)];
longpressGestureIDBadge.minimumPressDuration = 1;
[longpressGestureIDBadge setDelegate:self];
[btn_Barcode_IDBadgeView addGestureRecognizer:longpressGestureIDBadge];
[longpressGestureIDBadge release];

 
Leave a comment

Posted by on April 23, 2012 in Uncategorized

 

UIActionSheet + UIPicker Example

1 ) Which thing you have to declare in .h file ??
Ans :

UIPickerView *pickerView;
UIToolbar *pickerToolbar;
UIActionSheet *pickerViewPopup;
NSMutableArray *ary; ( array which you want to fill into uipickerview )

2 ) How can you open and close actionsheet ?
Ans :
just only two functions you need to implement is
– (void) showPicker – this is used to open actionsheet with picker
-(BOOL)closePicker:(id)sender – this is used to close actionsheet with picker.

>>> Implementation of showPicker function

– (void) showPicker {
pickerViewPopup = [[UIActionSheet alloc] initWithTitle:@”How many?”
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];

// Add the picker
pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0,44,0,0)];

pickerView.delegate = self;
pickerView.showsSelectionIndicator = YES; // note this is default to NO

pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
pickerToolbar.barStyle = UIBarStyleBlackOpaque;
[pickerToolbar sizeToFit];

NSMutableArray *barItems = [[NSMutableArray alloc] init];

UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];

UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(closePicker:)];
[barItems addObject:doneBtn];

[pickerToolbar setItems:barItems animated:YES];

[pickerViewPopup addSubview:pickerToolbar];
[pickerViewPopup addSubview:pickerView];
[pickerViewPopup showInView:self.view];
[pickerViewPopup setBounds:CGRectMake(0,0,320, 464)];

}

>>>> Implementation of ClosePicker Function

-(BOOL)closePicker:(id)sender
{
[pickerViewPopup dismissWithClickedButtonIndex:0 animated:YES];
[pickerToolbar release];
[pickerViewPopup release];
return YES;
}

 
1 Comment

Posted by on April 20, 2012 in Uncategorized

 

Sqlite Database Check , Read , Insert , Delete Functions

1 ) Usefull header File declarations :

Ans :
NSString *databaseName;
NSString *dbPath;
NSString *id1;
NSMutableArray *mainarray,*temparray;
NSMutableDictionary *tempdic;

2 ) Checking for database file exists or not ?
Ans :

-(void)checkdataBaseFile
{

NSArray *docPaths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);

NSString *docDir=[docPaths objectAtIndex:0];

dbPath=[docDir stringByAppendingPathComponent:databaseName];

BOOL success;

NSFileManager *fm=[NSFileManager defaultManager];

success=[fm fileExistsAtPath:dbPath];

if(success) return;

NSString *dbPathFromApp=[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:databaseName];

[fm copyItemAtPath:dbPathFromApp toPath:dbPath error:nil];

[fm release];

}

3 ) Insert Function

Ans :

code :

-(void)savedata

{
sqlite3 *database;

[self checkdata];

if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK)
{
NSString *sqlTmp=[NSString stringWithFormat:@”insert into tbl values(NULL,’%@’,’%@’)”,[[mainarray objectAtIndex:0]valueForKey:@”catid”],[[mainarray objectAtIndex:0]valueForKey:@”image”]];

const char *sqlStmt=[sqlTmp UTF8String];

sqlite3_stmt *cmp_sqlStmt;

int returnValue = sqlite3_prepare_v2(database, sqlStmt, -1, &cmp_sqlStmt, NULL);

((returnValue==SQLITE_OK) ? NSLog(@”Success”) : NSLog(@”UnSuccess”) );

sqlite3_step(cmp_sqlStmt);

sqlite3_finalize(cmp_sqlStmt);

}

sqlite3_close(database);

}

4 ) Read From DB File
Ans:
Code :
-(void)readdata

{
[self checkdata];

sqlite3 *database;

if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK)

{
NSString *sql=[NSString stringWithFormat:@”select * from tbl”];

const char *sqlStmt=[sql UTF8String];

sqlite3_stmt *cmp_sqlStmt;

if(sqlite3_prepare_v2(database, sqlStmt, -1, &cmp_sqlStmt, NULL)==SQLITE_OK)

{
while(sqlite3_step(cmp_sqlStmt)==SQLITE_ROW)
{
id1=[NSString stringWithUTF8String:(char*)sqlite3_column_text(cmp_sqlStmt, 2)];

//newStu=[[student alloc]initWithNo:id1];

[temparray addObject:id1];

//[newStu release];

}
}

sqlite3_finalize(cmp_sqlStmt);

}

sqlite3_close(database);
}

5 ) Delete function .
Ans:
Code:
-(void)DeleteAll record
{
sqlite3 *database;

[self checkdata];

if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK)

{
NSString *str=[NSString stringWithFormat:@”delete from tbl”];

const char *sqlStmt=[str UTF8String];

sqlite3_stmt *cmp_sqlStmt;

if(sqlite3_prepare_v2(database, sqlStmt, -1, &cmp_sqlStmt, NULL)==SQLITE_OK)
{
int returnValue = sqlite3_prepare_v2(database, sqlStmt, -1, &cmp_sqlStmt, NULL);
((returnValue==SQLITE_OK) ? NSLog(@”Success”) : NSLog(@”UnSuccess”) );
sqlite3_step(cmp_sqlStmt);
}
sqlite3_finalize(cmp_sqlStmt);
}

sqlite3_close(database);
}

 
1 Comment

Posted by on April 17, 2012 in Uncategorized