Presentation is loading. Please wait.

Presentation is loading. Please wait.

EEC-492/693/793 iPhone Application Development

Similar presentations


Presentation on theme: "EEC-492/693/793 iPhone Application Development"— Presentation transcript:

1 EEC-492/693/793 iPhone Application Development
Lecture 21 Wenbing Zhao & Nigamanth Sridhar 4/11/2019 4/11/2019 EEC492/693/793 - iPhone Application Development EEC492/693/793 - iPhone Application Development 1

2 Outline Accessing build-in applications Assignment:
Build the and PhotoLibrary apps 4/11/2019 4/11/2019 EEC492/693/793 - iPhone Application Development EEC492/693/793 - iPhone Application Development 2

3 Invoking Build-in Applications
[[UIApplication sharedApplication] openURL:url] NSString * String = url = [NSURL URLWithString: String]; Safari: url = [NSURL Phone: url = [NSURL SMS: url = [NSURL Drawback: calling app will be put to background, user must manually switch back to the app 4/11/2019 EEC492/693/793 - iPhone Application Development

4 Invoking the Build-in App without Leaving the Current App
Invoking the Mail composer UI Use MFMailComposeViewController Invoking the Message composer UI Use MFMessageComposeViewController -(IBAction) btnCompose (id) sender { MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self; [picker subject here”]; [picker body here” isHTML:NO]; [self presentModalViewController:picker animated:YES]; [picker release]; } - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { [controller dismissModalViewControllerAnimated:YES]; 4/11/2019 EEC492/693/793 - iPhone Application Development

5 The Image Picker Interface
UIImagePickerController Handles all user and device interactions UIViewController subclass UIImagePickerControllerDelegate Implemented by your delegate object Steps for using the image picker Check the source availability: isSourceTypeAvailable: class method Assign a delegate object Present the controller modally 4/11/2019 EEC492/693/793 - iPhone Application Development

6 Displaying the Image Picker
Called from a view controller if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) { UIImagePickerController* picker = [[UIImagePickerController alloc] init]; picker.sourceType = UIImagePickerControllerSourceTypeCamera; picker.delegate = self; // picker.allowsEditing = YES; [self presentModalViewController:picker animated:YES]; } enum { UIImagePickerControllerSourceTypePhotoLibrary, UIImagePickerControllerSourceTypeCamera, UIImagePickerControllerSourceTypeSavedPhotosAlbum }; typedef NSUInteger UIImagePickerControllerSourceType; 4/11/2019 EEC492/693/793 - iPhone Application Development

7 Defining Your Delegate Object
Accept case - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { // Check media type, and save or use the media here [self dismissModalViewControllerAnimated:YES]; // Dismiss the image picker [picker release]; } Cancel case - (void)imagePickerControllerDidCancel: (UIImagePickerController*)picker // Dismiss the image picker. [self dismissModalViewControllerAnimated:YES]; 4/11/2019 EEC492/693/793 - iPhone Application Development

8 EEC492/693/793 - iPhone Application Development
More on the Accept Case If an image was picked, a dictionary containing the image is passed in If a movie was picked, a filesystem URL for the movie is passed in - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *image; NSURL *mediaUrl = (NSURL *)[info valueForKey:UIImagePickerControllerMediaURL]; if (mediaUrl == nil) { image = (UIImage *) [info valueForKey:UIImagePickerControllerEditedImage]; if (image == nil) { //---original image selected--- image = (UIImage *) [info valueForKey:UIImagePickerControllerOriginalImage]; //---display the image--- } else //---edited image picked--- { // handle the image here else { //---video picked--- 4/11/2019 EEC492/693/793 - iPhone Application Development

9 Accessing the Videos in the Photo Library
Specify media types before launch the image picker (default is image only) NSArray *mediaTypes = [NSArray arrayWithObjects:kUTTypeImage, kUTTypeMovie, nil]; imagePicker.mediaTypes = mediaTypes; To play the video picked (works only in ios 4) #import <MediaPlayer/MediaPlayer.h> #import <MobileCoreServices/MobileCoreServices.h> MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:mediaUrl]; [[NSNotificationCenter defaultCenter] addObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player]; //---play partial screen--- player.view.frame = CGRectMake(0, 0, 320, 460); [self.view addSubview:player.view]; [player play]; 4/11/2019 EEC492/693/793 - iPhone Application Development

10 Accessing the Videos in the Photo Library
Cleaning up when video is done playing - (void) movieFinishedCallback:(NSNotification*) aNotification { MPMoviePlayerController *player = [aNotification object]; [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player]; [player.view removeFromSuperview]; [player autorelease]; } 4/11/2019 EEC492/693/793 - iPhone Application Development


Download ppt "EEC-492/693/793 iPhone Application Development"

Similar presentations


Ads by Google