Best place to start iOS app development. Here we combine multiple sources to make iOS development simple and easy way.
Tuesday, 31 December 2013
Monday, 23 December 2013
Mail with attachments in iOS?
HI,
Here am using MFMailCompose to create mail and attach a screen shot with it.
Its very easy ,and also for this we have to import "#import <MessageUI/MessageUI.h>".
In ViewController.h File
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
@interface ViewController : UIViewController <MFMailComposeViewControllerDelegate>
@property (strong, nonatomic) IBOutlet UIWebView *webview;
- (IBAction)openMail:(id)sender;
@end
In ViewController.m file
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface ViewController ()
{
NSArray *paths;
NSString *filename,*newPath;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)takescreenshotes{
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * data = UIImagePNGRepresentation(image);
filename=@"latest.png"; //create a custome file name for your screen shots
paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
newPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:filename];
[data writeToFile:newPath atomically:YES]; //Path to store the screen shots
UIImageWriteToSavedPhotosAlbum([UIImage imageWithData:data], nil, nil, nil);
}
- (IBAction)openMail:(id)sender
{
[self takescreenshotes];
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:@"Email Subject"];
NSArray *toRecipients = [NSArray arrayWithObjects:@"fisrtMail@example.com", nil];
[mailer setToRecipients:toRecipients];
UIImage *myImage = [UIImage imageWithContentsOfFile:newPath];
NSData *imageData = UIImagePNGRepresentation(myImage);
[mailer addAttachmentData:imageData mimeType:@"image/png" fileName:@"mobiletutsImage"];
NSString *emailBody = @"Please check the attached image: Naveen";
[mailer setMessageBody:emailBody isHTML:NO];
// only for iPad
// mailer.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentModalViewController:mailer animated:YES];
//[mailer release];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
message:@"Your device doesn't support the composer sheet"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
}
}
#pragma mark - MFMailComposeController delegate
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved: you saved the email message in the Drafts folder");
break;
case MFMailComposeResultSent:
NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send the next time the user connects to email");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail failed: the email message was nog saved or queued, possibly due to an error");
break;
default:
NSLog(@"Mail not sent");
break;
}
[self dismissModalViewControllerAnimated:YES];
}
@end
and the run time window looks like
You can download the code from here
Here am using MFMailCompose to create mail and attach a screen shot with it.
Its very easy ,and also for this we have to import "#import <MessageUI/MessageUI.h>".
In ViewController.h File
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
@interface ViewController : UIViewController <MFMailComposeViewControllerDelegate>
@property (strong, nonatomic) IBOutlet UIWebView *webview;
- (IBAction)openMail:(id)sender;
@end
In ViewController.m file
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface ViewController ()
{
NSArray *paths;
NSString *filename,*newPath;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)takescreenshotes{
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * data = UIImagePNGRepresentation(image);
filename=@"latest.png"; //create a custome file name for your screen shots
paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
newPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:filename];
[data writeToFile:newPath atomically:YES]; //Path to store the screen shots
UIImageWriteToSavedPhotosAlbum([UIImage imageWithData:data], nil, nil, nil);
}
- (IBAction)openMail:(id)sender
{
[self takescreenshotes];
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:@"Email Subject"];
NSArray *toRecipients = [NSArray arrayWithObjects:@"fisrtMail@example.com", nil];
[mailer setToRecipients:toRecipients];
UIImage *myImage = [UIImage imageWithContentsOfFile:newPath];
NSData *imageData = UIImagePNGRepresentation(myImage);
[mailer addAttachmentData:imageData mimeType:@"image/png" fileName:@"mobiletutsImage"];
NSString *emailBody = @"Please check the attached image: Naveen";
[mailer setMessageBody:emailBody isHTML:NO];
// only for iPad
// mailer.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentModalViewController:mailer animated:YES];
//[mailer release];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
message:@"Your device doesn't support the composer sheet"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];
}
}
#pragma mark - MFMailComposeController delegate
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved: you saved the email message in the Drafts folder");
break;
case MFMailComposeResultSent:
NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send the next time the user connects to email");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail failed: the email message was nog saved or queued, possibly due to an error");
break;
default:
NSLog(@"Mail not sent");
break;
}
[self dismissModalViewControllerAnimated:YES];
}
@end
and the run time window looks like
You can download the code from here
How to take screen shots programmatically ??
Hi.
In this tutorial ,am talking about how we can take screen shots programmatically instead of "Home+Power" button combination on your device.
It's very simple and i have only two files "ViewController.h" and "ViewController.m"
and you have to import "#import <QuartzCore/QuartzCore.h>".
here we go ..
in my ViewController.h file
i have one method for UIButton.
filename=@"latest.png"; //create a custome file name for your screen shots
paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
newPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:filename];
[data writeToFile:newPath atomically:YES]; //Path to store the screen shots
UIImageWriteToSavedPhotosAlbum([UIImage imageWithData:data], nil, nil, nil);
}
- (IBAction)openMail:(id)sender
{
[self takescreenshotes];
and my xib looks like
You can download the code from here
In this tutorial ,am talking about how we can take screen shots programmatically instead of "Home+Power" button combination on your device.
It's very simple and i have only two files "ViewController.h" and "ViewController.m"
and you have to import "#import <QuartzCore/QuartzCore.h>".
here we go ..
in my ViewController.h file
i have one method for UIButton.
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
- (IBAction)openMail:(id)sender;
@end
In my ViewController.m file
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
@interface ViewController ()
{
NSArray *paths;
NSString *filename,*newPath;
}
@end
@implementation ViewController
#import <QuartzCore/QuartzCore.h>
@interface ViewController ()
{
NSArray *paths;
NSString *filename,*newPath;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)takescreenshotes{
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * data = UIImagePNGRepresentation(image);
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)takescreenshotes{
UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * data = UIImagePNGRepresentation(image);
filename=@"latest.png"; //create a custome file name for your screen shots
paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
newPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:filename];
[data writeToFile:newPath atomically:YES]; //Path to store the screen shots
UIImageWriteToSavedPhotosAlbum([UIImage imageWithData:data], nil, nil, nil);
}
- (IBAction)openMail:(id)sender
{
[self takescreenshotes];
}
@end
You can download the code from here
Monday, 9 December 2013
QR Code Reader
The ZBar Barcode Reader iPhone® App is a simple demonstration of the ZBar library on the iPhone 3GS and iPhone 4 platforms. Using the app you can:
- Scan EAN/UPC codes and link to web sites that perform product searches. Links to Google, Amazon and the Internet UPC Database are predefined.
- Scan QR codes containing URLs and link directly to the web site.
- Scan QR codes containing an E-mail address and send mail.
- Scan a UPS or FedEx tracking number and link to the package tracking web page.
- Maintain a simple list of scanned barcodes.
- Send an E-mail containing a single barcode or your entire list of scanned barcodes.
- Cut and paste barcode data into other apps.
Please note that this app is just about the barcodes; specifically it is not a full featured "shopping app". We do not scrape the web for product or pricing information, perform localized searches or implement any of the other fancy features that you would expect to find in such an application.
Subscribe to:
Posts (Atom)