. (Mail), (Phone), (Safari), SMS, (Calendar).. SDK API... POP3 IMAP, Exchange Yahoo Gmail (rich) HTML (Mail).
Chapter 13.... (Mail)., (Mail).. 1. Xcode View based Application (iphone) Emails. 2. EmailsViewController.xib. 3. ( 13 1 ). Label TextField TextView( ) Button ttp://jpub.tistory.com/ http://peterslab.tistory.com/
373 4. EmailsViewController.h. #import <UIKit/UIKit.h> @interface EmailsViewController : UIViewController { IBOutlet UITextField *to; IBOutlet UITextField *subject; IBOutlet UITextView *body; @property (nonatomic, retain) UITextField *to; @property (nonatomic, retain) UITextField *subject; @property (nonatomic, retain) UITextView *body; -(IBAction) btnsend: (id) sender; @end 5., File s Owner Control to subject, body. 6. Control File s Owner, btnsend:. 7. EmailsViewController.m. #import "EmailsViewController.h" @implementation EmailsViewController @synthesize to, subject, body; - (void) sendemailto:(nsstring *) tostr withsubject:(nsstring *) subjectstr withbody:(nsstring *) bodystr { NSString *emailstring = [[NSString alloc] initwithformat:@"mailto:?to=%@&subject=%@&body=%@", [tostr stringbyaddingpercentescapesusingencoding: NSASCIIStringEncoding], [subjectstr stringbyaddingpercentescapesusingencoding:
Chapter 13 NSASCIIStringEncoding], [bodystr stringbyaddingpercentescapesusingencoding: NSASCIIStringEncoding]]; [[UIApplication sharedapplication] openurl:[nsurl URLWithString:emailString]]; [emailstring release]; -(IBAction) btnsend: (id) sender { [self sendemailto:to.text withsubject:subject.text withbody:body.text]; - (void)dealloc { [to release]; [subject release]; [body release]; [super dealloc]; 8. Command R. 13 2., Send (Mail). (Mail) Send.
375 (Mail) sendemailto:withsubject:withbody:. NSString *emailstring = [[NSString alloc] initwithformat:@"mailto:?to=%@&subject=%@&body=%@", [tostr stringbyaddingpercentescapesusingencoding: NSASCIIStringEncoding], [subjectstr stringbyaddingpercentescapesusingencoding: NSASCIIStringEncoding], [bodystr stringbyaddingpercentescapesusingencoding: NSASCIIStringEncoding]]; mailto: URL. to subject, body. URL NSString stringbyaddingpercentescapes UsingEncoding:. (Mail) (singleton) sharedapplication, openurl: (Mail). [[UIApplication sharedapplication] openurl:[nsurl URLWithString:emailString]]; NOTE Send (Mail). (foreground).. MFMailComposeViewController..
Chapter 13 1.. EmailsViewController.xib Round Rect button ( 13 3 ). 2. Xcode Frameworks Add Existing Frameworks..., MessageUI.framework ( 13 4 ). 3. EmailsViewController.h. #import <UIKit/UIKit.h> #import <MessageUI/MFMailComposeViewController.h> @interface EmailsViewController : UIViewController <MFMailComposeViewControllerDelegate> { IBOutlet UITextField *to; IBOutlet UITextField *subject; IBOutlet UITextView *body; @property (nonatomic, retain) UITextField *to; @property (nonatomic, retain) UITextField *subject; @property (nonatomic, retain) UITextView *body;
377 -(IBAction) btnsend: (id) sender; -(IBAction) btncomposeemail: (id) sender; @end 4., Compose Email Control File s Owner btncomposeemail:. 5. EmailsViewController.m. #import "EmailsViewController.h" @implementation EmailsViewController @synthesize to, subject, body; -(IBAction) btncomposeemail: (id) sender { MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailcomposedelegate = self; [picker setsubject:@"email subject here"]; [picker setmessagebody:@"email body here" ishtml:no]; [self presentmodalviewcontroller:picker animated:yes]; [picker release]; - (void)mailcomposecontroller:(mfmailcomposeviewcontroller*)controller didfinishwithresult:(mfmailcomposeresult)result error:(nserror*)error { [controller dismissmodalviewcontrolleranimated:yes]; 6. Command R. Compose Email (Mail) ( 13 5 ).,.
Chapter 13 MFMailComposeViewController (modally),.. (Safari), URL openurl:. [[UIApplication sharedapplication] openurl:[nsurl URLWithString: @"http://www.apple.com"]]; http://www.apple.com ( 13 6 ). URL. [[UIApplication sharedapplication] openurl:[nsurl URLWithString: @"tel:02-123-4567"]]; NOTE SMS URL. [[UIApplication sharedapplication] openurl:[nsurl URLWithString: @"sms:02-123-4567"]];
379 SMS ( 13 7 ).. NOTE SDK 4 SMS.. SMS 1.. EmailsViewController.h. #import <UIKit/UIKit.h> #import <MessageUI/MFMailComposeViewController.h> #import <MessageUI/MFMessageComposeViewController.h>
Chapter 13 @interface EmailsViewController : UIViewController <MFMailComposeViewControllerDelegate, MFMessageComposeViewControllerDelegate> { IBOutlet UITextField *to; IBOutlet UITextField *subject; IBOutlet UITextView *body; @property (nonatomic, retain) UITextField *to; @property (nonatomic, retain) UITextField *subject; @property (nonatomic, retain) UITextView *body; -(IBAction) btnsend: (id) sender; -(IBAction) btncomposeemail: (id) sender; -(IBAction) btncomposesms: (id) sender; @end 2. EmailsViewController.xib, Round Rect button Compose SMS. 3. Control File s Owner btncomposesms:. 4. EmailsViewController.m. -(IBAction) btncomposesms: (id) sender { MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init]; picker.messagecomposedelegate = self; [picker setbody:@"this message sent from the application."]; [self presentmodalviewcontroller:picker animated:yes]; [picker release]; - (void)messagecomposeviewcontroller:(mfmessagecomposeviewcontroller *)controller didfinishwithresult:(messagecomposeresult)result { [controller dismissmodalviewcontrolleranimated:yes];
381 5. Command R SMS ( 13 8 ).. MFMessageComposeViewController SDK API. SMS,. SMS. ( 4 4 2 ). (Photos). (Photos).. (Photos).
Chapter 13 (Photos). SDK (Photos) UI UIImagePickerController.. 1. Xcode View based Application (iphone) PhotoLibrary. 2. PhotoLibraryViewController.xib. 3. ( 13 9 ). Round Rect Button ImageView 4. ImageView Attributes Inspector Mode Aspect Fit ( 13 10 ). 5. PhotoLibraryViewController.h. #import <UIKit/UIKit.h> @interface PhotoLibraryViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate> { IBOutlet UIImageView *imageview; UIImagePickerController *imagepicker;
383 @property (nonatomic, retain) UIImageView *imageview; -(IBAction) btnclicked: (id) sender; @end 6., File s Owner Control imageview ImageView. 7. Control File s Owner btnclicked:. 8. PhotoLibraryViewController.m. #import "PhotoLibraryViewController.h" @implementation PhotoLibraryViewController @synthesize imageview;
Chapter 13 - (void)viewdidload { imagepicker = [[UIImagePickerController alloc] init]; [super viewdidload]; - (IBAction) btnclicked: (id) sender { imagepicker.delegate = self; imagepicker.sourcetype = UIImagePickerControllerSourceTypePhotoLibrary; //--- --- [self presentmodalviewcontroller:imagepicker animated:yes]; - (void)imagepickercontroller:(uiimagepickercontroller *)picker didfinishpickingmediawithinfo:(nsdictionary *)info { UIImage *image; NSURL *mediaurl; mediaurl = (NSURL *)[info valueforkey: UIImagePickerControllerMediaURL]; if (mediaurl == nil) { image = (UIImage *) [info valueforkey:uiimagepickercontrollereditedimage]; if (image == nil) { //--- --- image = (UIImage *) [info valueforkey:uiimagepickercontrolleroriginalimage]; //--- --- imageview.image = image; else { //--- --- //--- (crop) --- CGRect rect = [[info valueforkey:uiimagepickercontrollercroprect] CGRectValue]; //--- --- imageview.image = image; else { //--- --- //--- ---
385 //--- --- [picker dismissmodalviewcontrolleranimated:yes]; - (void)imagepickercontrollerdidcancel:(uiimagepickercontroller *)picker { //---, --- [picker dismissmodalviewcontrolleranimated:yes]; - (void)dealloc { [imageview release]; [imagepicker release]; [super dealloc]; 9. Command R. 10. Load Photo Library. Photo Albums. ( 13 11 ),. ImageView ( 13 12 ).
Chapter 13 UI (Photo Library) UIImagePickerController. UIImagePickerControllerDelegate. UINavigationControllerDelegate. UIImagePickerController. PhotoLibraryViewController.h. @interface PhotoLibraryViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate> {... Load Photo Library UIImagePickerController,. - (IBAction) btnclicked: (id) sender { imagepicker.delegate = self; imagepicker.sourcetype = UIImagePickerControllerSourceTypePhotoLibrary; //--- --- [self presentmodalviewcontroller:imagepicker animated:yes];,. imagepicker.allowsediting = YES;, UIImagePickerControllerSourceTypePhotoLibrary,. UIImagePickerControllerSourceTypeCamera. UIImagePickerControllerSourceTypeSavedPhotosAlbum Photo Albums.
387 /, imagepickercontroller:didfinishpickingmediawithinfo:. - (void)imagepickercontroller:(uiimagepickercontroller *)picker didfinishpickingmediawithinfo:(nsdictionary *)info { UIImage *image; NSURL *mediaurl; mediaurl = (NSURL *)[info valueforkey:uiimagepickercontrollermediaurl]; if (mediaurl == nil) { image = (UIImage *) [info valueforkey:uiimagepickercontrollereditedimage]; if (image == nil) { //--- --- image = (UIImage *) [info valueforkey:uiimagepickercontrolleroriginalimage]; //--- --- imageview.image = image; else { //--- -- //--- (crop) --- CGRect rect = [[info valueforkey:uiimagepickercontrollercroprect] CGRectValue]; //--- --- imageview.image = image; else { //--- --- //--- --- //--- --- [picker dismissmodalviewcontrolleranimated:yes]; info:. valueforkey:,. mediaurl = (NSURL *)[info valueforkey:uiimagepickercontrollermediaurl];
Chapter 13 imagepickercontrollerdidcancel:.. - (void)imagepickercontrollerdidcancel:(uiimagepickercontroller *)picker { //--- --- [picker dismissmodalviewcontrolleranimated:yes]; (Photo Library).,. 1.. Xcode Frameworks MediaPlayer. framework MobileCoreServices.framework ( 13 13 ).
389 2. PhotoLibraryViewController.h. #import <UIKit/UIKit.h> #import <MediaPlayer/MediaPlayer.h> #import <MobileCoreServices/MobileCoreServices.h> @interface PhotoLibraryViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate> { IBOutlet UIImageView *imageview; UIImagePickerController *imagepicker; @property (nonatomic, retain) UIImageView *imageview; -(IBAction) btnclicked: (id) sender; @end 3. PhotoLibraryViewController.m. - (IBAction) btnclicked: (id) sender { imagepicker.delegate = self; imagepicker.sourcetype = UIImagePickerControllerSourceTypePhotoLibrary; NSArray *mediatypes = [NSArray arraywithobjects:kuttypeimage, kuttypemovie, nil]; imagepicker.mediatypes = mediatypes; //--- --- [self presentmodalviewcontroller:imagepicker animated:yes]; - (void)imagepickercontroller:(uiimagepickercontroller *)picker didfinishpickingmediawithinfo:(nsdictionary *)info { UIImage *image; NSURL *mediaurl; mediaurl = (NSURL *)[info valueforkey:uiimagepickercontrollermediaurl]; if (mediaurl == nil) { image = (UIImage *) [info valueforkey:uiimagepickercontrollereditedimage]; if (image == nil) { //--- --- image = (UIImage *)
Chapter 13 [info valueforkey:uiimagepickercontrolleroriginalimage]; //--- --- imageview.image = image; else { //--- --- //--- (crop) --- CGRect rect = [[info valueforkey:uiimagepickercontrollercroprect] CGRectValue]; //--- --- imageview.image = image; else { //--- --- MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initwithcontenturl:mediaurl]; [[NSNotificationCenter defaultcenter] addobserver:self selector:@selector(moviefinishedcallback:) name:mpmovieplayerplaybackdidfinishnotification object:player]; //--- --- player.view.frame = CGRectMake(0, 0, 320, 460); [self.view addsubview:player.view]; [player play]; //--- --- [picker dismissmodalviewcontrolleranimated:yes]; - (void) moviefinishedcallback:(nsnotification*) anotification { MPMoviePlayerController *player = [anotification object]; [[NSNotificationCenter defaultcenter] removeobserver:self name:mpmovieplayerplaybackdidfinishnotification object:player]; [player.view removefromsuperview];
391 [player autorelease]; 4. Command R. Choose ( 13 14 ).. UIImagePickerController. UIImagePickerController mediatypes. NSArray. kuttypeimage kuttypemovie. imagepicker.sourcetype = UIImagePickerControllerSourceTypePhotoLibrary; NSArray *mediatypes = [NSArray arraywithobjects:kuttypeimage, kuttypemovie, nil]; imagepicker.mediatypes = mediatypes; //--- --- [self presentmodalviewcontroller:imagepicker animated:yes];
Chapter 13 MPMoviePlayerController. if (mediaurl == nil) { //... //... else { //--- --- MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initwithcontenturl:mediaurl]; [[NSNotificationCenter defaultcenter] addobserver:self selector:@selector(moviefinishedcallback:) name:mpmovieplayerplaybackdidfinishnotification object:player]; //--- --- player.view.frame = CGRectMake(0, 0, 320, 460); [self.view addsubview:player.view]; [player play]; //--- --- [picker dismissmodalviewcontrolleranimated:yes];. - (void) moviefinishedcallback:(nsnotification*) anotification { MPMoviePlayerController *player = [anotification object]; [[NSNotificationCenter defaultcenter] removeobserver:self name:mpmovieplayerplaybackdidfinishnotification object:player]; [player.view removefromsuperview]; [player autorelease];
393 (Photo Library),., UIImagePickerController.... 1.. PhotoLibraryViewController.m ( ). - (IBAction) btnclicked: (id) sender { imagepicker.delegate = self; //--- --- /* imagepicker.sourcetype = UIImagePickerControllerSourceTypePhotoLibrary; NSArray *mediatypes = [NSArray arraywithobjects:kuttypeimage, kuttypemovie, nil]; imagepicker.mediatypes = mediatypes; */ //--- --- imagepicker.sourcetype = UIImagePickerControllerSourceTypeCamera; NSArray *mediatypes = [NSArray arraywithobjects:kuttypeimage, kuttypemovie, nil]; imagepicker.mediatypes = mediatypes; imagepicker.cameracapturemode = UIImagePickerControllerCameraCaptureModeVideo; imagepicker.allowsediting = YES; //--- --- [self presentmodalviewcontroller:imagepicker animated:yes]; 2. PhotoLibraryViewController.m.
Chapter 13 - (NSString *) filepath: (NSString *) filename { NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsdir = [paths objectatindex:0]; return [documentsdir stringbyappendingpathcomponent:filename]; - (void) saveimage{ //--- --- NSData *imagedata = [NSData datawithdata:uiimagepngrepresentation(imageview.image)]; //--- --- [imagedata writetofile:[self filepath:@"mypicture.png"] atomically:yes]; 3.. - (void)imagepickercontroller:(uiimagepickercontroller *)picker didfinishpickingmediawithinfo:(nsdictionary *)info { UIImage *image; NSURL *mediaurl; mediaurl = (NSURL *)[info valueforkey:uiimagepickercontrollermediaurl]; if (mediaurl == nil) { image = (UIImage *) [info valueforkey:uiimagepickercontrollereditedimage]; if (image == nil) { //--- --- image = (UIImage *) [info valueforkey:uiimagepickercontrolleroriginalimage]; //--- --- imageview.image = image; //--- --- [self saveimage]; else { //--- --- //--- (crop) --- CGRect rect = [[info valueforkey:uiimagepickercontrollercroprect]
395 CGRectValue]; //--- --- imageview.image = image; //--- --- [self saveimage]; else { //--- --- MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initwithcontenturl:mediaurl]; [[NSNotificationCenter defaultcenter] addobserver:self selector:@selector(moviefinishedcallback:) name:mpmovieplayerplaybackdidfinishnotification object:player]; //--- --- player.view.frame = CGRectMake(0, 0, 320, 460); [self.view addsubview:player.view]; [player play]; //--- --- [picker dismissmodalviewcontrolleranimated:yes]; 4. Command R. 5. Load Photo Library. ( 13 15 ) Documents. ( 13 16 ).
Chapter 13. imagepicker.sourcetype = UIImagePickerControllerSourceTypeCamera; imagepickercontroller:didfinishpicking MediaWithInfo:,.
397. filepath: Documents. - (NSString *) filepath: (NSString *) filename { NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsdir = [paths objectatindex:0]; return [documentsdir stringbyappendingpathcomponent:filename]; saveimage:, MyPicture.png filepath:. - (void) saveimage{ //--- --- NSData *imagedata = [NSData datawithdata:uiimagepngrepresentation(imageview.image)]; //--- --- [imagedata writetofile:[self filepath:@"mypicture.png"] atomically:yes]; URL, MediaPlayer MPMoviePlayerController. NOTE UIImagePickerController UIImagePickerController cameradevice UIImagePickerControllerCameraDeviceRear UIImagePickerControllerCameraDeviceFront NOTE
Chapter 13. URL SMS (Mail), (Safari), (Phone). SMS, SDK (Photo Library). 1. SMS (Mail), (Safari), (Phone) URL 2. Image Picker UI 3. Mail Composer UI 4. Message Composer UI E.
399 NSString *emailstring = @"mailto:?to=user@email.com&subject=subject&body=body", [[UIApplication sharedapplication] openurl:[nsurl URLWithString:emailString]]; [[UIApplication sharedapplication] openurl:[nsurl URLWithString: @"http://www.apple.com"]]; [[UIApplication sharedapplication] openurl:[nsurl URLWithString: @"tel:0123456789"]]; [[UIApplication sharedapplication] openurl:[nsurl URLWithString: @"sms:0123456789"]]; UIImagePickerController UINavigation ControllerDelegate MFMailComposeViewController MFMessageComposeViewController