1 / 22

Wednesday 2-4, DH 1046

Wednesday 2-4, DH 1046. COMP 446 / ELEC 446 Mobile Device Applications. Scott Cutler Professor in the Practice of Computer Technology Department of Computer Science Department of Electrical and Computer Engineering cutler@rice.edu 10/12/11. Today’s Agenda. Events of the week

yasuo
Télécharger la présentation

Wednesday 2-4, DH 1046

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Wednesday 2-4, DH 1046 COMP 446 / ELEC 446 Mobile Device Applications Scott Cutler Professor in the Practice of Computer Technology Department of Computer Science Department of Electrical and Computer Engineering cutler@rice.edu 10/12/11

  2. Today’s Agenda • Events of the week • Final Project Schedule • Web Services(abbreviated) • Memory Management Summary Sheet • Controllers of Controllers, Gesture Recognizers • Review of current assignment • Next Week COMP 446 / ELEC 446 - Week 8

  3. Events of the Week • Apple's Steve Jobs has passed away • What I learned from Steve Jobs (Guy Kawasaki) • The 1971 article that inspired Steve Jobs • Apple iPhone 4S gets lukewarm analyst response • iPhone 4S preorders top 1 million in single day • Galaxy Nexus launch delayed due to Jobs' death • Unlocked iPhone 4S coming in November • Netflix cancels Qwiksterspinoff • Xbox 360 sales nearly double that of Wii's, analyst says • Amazon's Kindle Fire tablet hit by patent lawsuit • HP near decision on WebOS group, report says • Introducing Dart, Google's answer to JavaScript • Facebook accused of copying MyPad'siOSapp • RIM Hit With Worldwide BlackBerry Outage, Shareholder Unrest COMP 446 / ELEC 446 - Week 8

  4. COMP 446 Syllabus • 8/24/11 Introduction / What makes mobile apps special Videos: Lecture 1. Introduction to Cocoa Touch, Objective-C, Tools, and MVC (September 21, 2010) Lecture 2. Building a Simple Calculator (September 23, 2010) Assignment: #1 and #1 Walkthrough - Calculator Due: Preferably watch videos this week, definitely by 8/30. Assignment due 9/1/11. • 8/31/11 Discussion of first applications, Development Environment Videos: Lecture 3. Objective-C and Foundation Frameworks (September 28, 2010) Lecture 4. Foundation and Memory Management (September 30, 2010) Assignment: #2 Function Calculator (Due 9/15/11) • 9/7/11 Intro to Cocoa Touch, Objective-C, Using Objective-C, Foundation framework Videos: Assignment: • 9/14/11Memory Management Videos: Lecture 5. Protocols and Views (October 5, 2010) Lecture 6. Application & View Controller Lifecycle, Navigation Controller (October 7, 2010) Assignment: #3 Graphing Calculator (Due 9/22/11) • 9/21/11 iPhone (pseudo) Web Apps Videos: Lecture 7. More Controllers of Controllers, iPad, Universal Applications (October 12, 2010) Lecture 8. Gesture Recognizers (October 14, 2010) Assignment: #4 Universal Calculator (Due 9/29/11) COMP 446 / ELEC 446 - Week 8

  5. COMP 446 Syllabus • 9/28/11 Creating and Consuming Web Services Videos: Lecture 9. Image View, Web View, and Scroll View (October 19, 2010) Lecture 10. Table View (October 21, 2010)Assignment: #5 Pictures Places (Due 10/13/11) • 10/5/11 SQL 101 Videos: Lecture 11. Persistence (October 26, 2010) Lecture 12. Core Data and Table Views (October 28, 2010) Assignment: #6 Core Data Places (Due 10/20/11, but watch lectures prior to 10/12/11 class) • 10/12/11 Core Data Demo / Final Project discussion and Pairing Videos: Debugging Tools (October 22, 2010)Kleiner Perkins iFund (October 15, 2010) Assignment: Final Project Proposal (Due 10/18/11 along with Core Data Places due 10/20/11) • 10/19/11 iOS 5 Videos: Lecture 13. Blocks and Multithreading (November 2, 2010) Lecture 14. Core Location and Map Kit (November 9, 2010) Assignment: Final Project, Stage 1 (Due 10/27/11) • 10/26/11 Android Videos: Lecture 15. Editable Text, Modal View Controllers, and View Animation (Nov 11, 2010) Lecture 16. Core Motion, Segmented Control, and Alerts (November 16, 2010) Assignment: Advanced Feature App (Due 11/03/11) COMP 446 / ELEC 446 - Week 8

  6. COMP 446 Syllabus • 11/2/11 Windows Phone 7, Final Project Prep Videos: Lecture 17. Media (November 18, 2010) Lecture 18. Accessibility on iOS: Make an App for Everyone (November 30, 2010) Assignment: Final Project, Stage 2 (Due 11/10/2011) • 11/09/11 Final Project Prep / iPhone v. Android v. Windows Phone 7 group discussion Videos: Lessons from Bezos, Pincus, Young: CEO 2.0 (November 12, 2010) (Optional) LinkedIn: Shipping with CoreData (November 5, 2010) (Optional) Assignment: Final Project, Stage 3 (Due 11/17/2011) • 11/16/11 Final Project Prep Videos: Building Flipboard (November 19, 2010) (Optional) Assignment: Final Project Presentation (Due 11/30/2011) • 11/23/11 Thanksgiving – Continue Final Projects on your own • 11/30/11 Demonstrate Final Projects to class • 12/4/11 Class Offsite – Sunday (tentative) • Finals Submission of final code due by official finals date COMP 446 / ELEC 446 - Week 8

  7. Core Data Uses Big Words • NSManagedObject • Just an object representing something from the database • NSManagedObjectContext • Similar to CGContextRef • Simple call to get via method in App Delegate automatically created if you select Core Data (difficult to add Core Data if not set at beginning) • NSFetchRequest • For getting items from the database • NSSortDescriptor • For describing one layer of sorts • NSArray of NSSortDescriptors given to NSFetchRequest • NSPredicate or NSCompoundPredicate • Condition clause to determine which records match request • NSCompoundPredicate used when there are multiple conditions COMP 446 / ELEC 446 - Week 8

  8. Using Managed Objects • Get a context • self.managedObjectContext • <managedObject>.managedObjectContext • Save a context • self.saveContext • Create objects • [NSEntityDescriptioninsertNewObjectForEntityForName(NSString *)inManagedObjectContext:(NSManagedObjectContext *)]; • Fetch via NSFetchRequest COMP 446 / ELEC 446 - Week 8

  9. NSFetchRequest • NSFetchRequest *request = [[NSFetchRequestalloc] init]; • request.entity = [MSEntityDescriptionentityForName:xxxinManagedObjectContext:yyy]; • request.fetchBatchSize= • request.fetchLimit = • request.sortDescriptors=[NSArrayarrayWithObject:sortDescriptor]; • request.predicate= … COMP 446 / ELEC 446 - Week 8

  10. NSPredicate • [NSPredicatepredicateWithFormat:@”object <adverb> %@”, value]; • Examples • @”uniqueId=%@”, value • @“%@ in tags”, (NSManagedObject *) • @“viewed > %@”, (NSDate *) • @name contains[c] %@”. (NSString *) • Use a compound predicate to include And and Or COMP 446 / ELEC 446 - Week 8

  11. NSSortDescriptor • Array of sort descriptors used in NSFetchRequest • [[NSSortDescriptoralloc] initWithKey:@”foo” ascending:(BOOL)]; • Optional selector argument COMP 446 / ELEC 446 - Week 8

  12. Core Data Demo • Fetch a lost of photos from Flickr • Display a table view full of the photographers who took those photos • Push a list of that photographer’s photos when the photographer is clicked on • Display a photo in a UIScrollView when a photo is clicked on (not in Demo) • Basically same demo as in the CS193p video COMP 446 / ELEC 446 - Week 8

  13. Core Data Demo Steps #1 • Create new Window Based app (Bugshutter) (Taken from CS193p Shutterbug) • Using Core Data • Create Photo and Photographer entities • Starts off as NSManagedObject. Will be updated when classes written. • Photo Attribute – imageURL (String) • Photo Attribute – title (string) • Photo Attribute – uniqueId (string) • Photographer Attribute – name (string) • Photographer Relationship – photos, To-Many, Destination Photo, No inverse yet • Photo Relationship – whoTook, Destination Photographer, Inverse photos, not Too Many • Create custom classes by: • Click on one, Create new file of type Managed Object Class, (Editor – Create NSManagedObject Subclass), Select all objects, move into classes • Import CoreDataTableViewController and FlickerFetcher (and JSON) Classes (with copy) • Make sure recentGeoreferencedPhotos is in FlickrFetcher • Add code to get photos from Flickr to AppDelegate • Import FlickrFetcher.h, • NSArray *photos =[FlickrFetcherrecentGeoreferencedPhotos]; • for (NSDictionary *photoInfo in photos){} • In Photo.h, add method + (Photo *)photoWithFlickrData:(NSDictionary *)flickrDatainManagedObjectContext:(NSManagedObjectContext *)context; COMP 446 / ELEC 446 - Week 8

  14. Core Data Demo Steps #2 • In Photo.m create: + (Photo *)photoWithFlickrData:(NSDictionary *)flickrDatainManagedObjectContext:(NSManagedObjectContext *)context{ Photo *photo=nil;NSFetchRequest *request = [[NSFetchRequestalloc] init];request.entity = [NSEntityDescriptionentityForName:@”Photo” inManagedObjectContext:context];request.predicate = [NSPredicatepredicateWithFormat:@”uniqueId=%@”, [flickrDataobjectForKey:@”id”]];NSError *error = nil; photo = [[context executeFetchRequest:request error:&error] lastObject]; if (!error && !photo) { photo = [NSEntityDescriptioninsertNewObjectForEntityForName:@”Photo” inManagedObjectContext:context];photo.uniqueId = [flickrDataobjectForKey:@”id”];photo.title = [flickrDataobjectForKey:@”title”];photo.imageURL = [FlickrFetcherurlStringForPhotoWithFlickrInfo:flickrDataformat:FlickrFetcherPhotoFormateLarge];photo.whoTook = [Photographer photographerWithFlickrData:flickrDatainManagedObjectContext:context]; } return photo;} • #import FlickerFetcher.h and Photographer.h • In Photographer.m, copy and past photoWithFlickData code. COMP 446 / ELEC 446 - Week 8

  15. Core Data Demo Steps #3 • In Photographer.m, copy and past photoWithFlickData code. • + (Photographer*)photographerWithFlickrData:(NSDictionary *)flickrDatainManagedObjectContext:(NSManagedObjectContext *)context{ Photographer *photographer=nil;NSFetchRequest *request = [[NSFetchRequestalloc] init];request.entity = [NSEntityDescriptionentityForName:@”Phototographer” inManagedObjectContext:context];request.predicate = [NSPredicatepredicateWithFormat:@”name=%@”, [flickrDataobjectForKey:@”ownername”]];NSError *error = nil; photographer = [[context executeFetchRequest:request error:&error] lastObject]; if [!error && !photographer) {photographer = [NSEntityDescriptioninsertNewObjectForEntityForName:@”Photographer” inManagedObjectContext:context]; photographer.name = [flickrDataobjectForKey:@”ownername”];photo.title = [flickrDataobjectForKey:@”title”];photo.imageURL = [FlickrFetcherurlStringForPhotoWithFlickrInfo:flickrDataformat:FlickrFetcherPhotoFormateLarge];photo.whoTook=[Photographer photographerWithFlickrData:flickrDatainManagedObjectContext:context]; }return photographer;} • In Photographer.h, add: + (Photographer*)photographerWithFlickrData:(NSDictionary *)flickrDatainManagedObjectContext:(NSManagedObjectContext *)context; COMP 446 / ELEC 446 - Week 8

  16. Core Data Demo Steps #4 • Back in AppDelegate, add #import “Photo.h” and finish didFinish…. • NSArray *photos =[FlickrFetcherrecentGeoreferencedPhotos];for (NSDictionary *photoInfo in photos){Photo *photo = [Photo photoWithFlickrData:photoInfoinManagedObjectContext:self.managedObjectContext];} [self saveContext]; • File, new Class PhotographersTableViewController • #import “CoreDataTableViewController.h” • Subclass of :CoreDataTableViewController • - initInManagedObjectContext: (NSManagedObjectContext *)context; COMP 446 / ELEC 446 - Week 8

  17. Core Data Demo Steps #5 • PhotographersTableViewController.m • - initInManagedObjectContext: (NSManagedObjectContext *)context{ if (self = [super initWithStyle:UITableViewStylePlain]) {NSFetchRequest *request = [[NSFetchRequestalloc] init];request.entity = [NSEntityDescriptionentityForName:@”Photographer” inManagedObjectContext:context];request.sortDescriptors=[NSArrayarrayWithObject:[NSSortDescriptorsortDescriptorWithKey:@”name” ascending:YES]request.predicate = nil;request.fetchBatchSize = 20;NSFetchedResultsController *frc = [[NSFetchedResultsControlleralloc]initWithFetchRequest:requestmanagedObjectContext:contextsectionNameKeyPath: nil cacheName:@”MyPhotoCache”]; [request release];self.fetchedResultsController=frc; [frc release];self.titleKey = @”name”; }return self;} • -(void) managedObjectSelected:(NSManagedObject *)managedObject{} COMP 446 / ELEC 446 - Week 8

  18. Core Data Demo Steps #6 • Back in AppDelegate, add #import “PhotographersTableViewController.h” and finish didFinish…. • NSArray *photos =[FlickrFetcherrecentGeoreferencedPhotos];for (NSDictionary *photoInfo in photos){Photo *photo = [Photo photoWithFlickrData:photoInfoinManagedObjectContext:self.managedObjectContext];} [self saveContext];PhotographersTableViewController *ptvc = [[PhotographersTableViewControlleralloc] initInManagedObjectContext:self.managedObjectContext];UINavigationController *navcon = [[UINavigationControlleralloc] init];[navconpushViewController:ptvcannimated:NO];[self.windowaddSubview:navcon.view];[self.windowmakeKeyAndVisible];return YES; COMP 446 / ELEC 446 - Week 8

  19. Core Data Demo Steps #7 • Create PhotosByPhotographerTableViewController • Import #”CoreDataTableViewController.h” and “Photographer.h). Subclass CoreTableViewController • -initWithPhotographer:(Photographer *)photographer; //(not inManagedObjectContext) • Copy and paste from PhotographersTableViewController.m • -initWithPhotographer:(Photographer *)photographer{NSManagedObjectContext *context=photographer.managedObjectContext; if (self = [super initWithStyle:UITableViewStylePlain]) {NSFetchRequest *request = [[NSFetchRequestalloc] init];request.entity = [NSEntityDescriptionentityForName:@”Photo” inManagedObjectContext:context];request.sortDescriptors=[NSArrayarrayWithObject:[NSSortDescriptorsortDescriptorWithKey:@”title” ascending:YES]request.predicate = [NSPredicatepredicateWithFormat:@”whoTook=%@”, photographer];request.fetchBatchSize = 20;NSFetchedResultsController *frc = [[NSFetchedResultsControlleralloc]initWithFetchRequest:requestmanagedObjectContext:contextsectionNameKeyPath: nil cacheName:nil];request release];self.fetchedResultsController=frc;[frc release];self.titleKey = @”title”;} • -(void) managedObjectSelected:(NSManagedObject *)managedObject{} COMP 446 / ELEC 446 - Week 8

  20. Core Data Demo Steps #8 • Back in PhotographersTableViewController.m • #import “PhotosByPhotographerTableViewController.h” • -(void) managedObjectSelected:(NSManagedObject *)managedObject{ Photographer *photographer = (Photographer *)managedObject;PhotosByPhotographerTableViewController *pbptvc=[[PhotosByPhotographerTableViewControlleralloc] initWithPhotographer:photographer]; [self.navigationControllerpushViewController:pbptvcanimated:YES]; [pbptvc release];} COMP 446 / ELEC 446 - Week 8

  21. Assignment #6 • Staggered overlapping due date with Assignment #5 • Three major parts • Core Data version of Assignment #5 • Addition of Favorite Places • Caching of image data to sandbox • Item 1 required, Items 2 and 3 required if you want possibility of A+ in class • While not required, if you want to create great apps, you should also do Assignment #7 – multi thread • Items 2 and 3 can be submitted at any time before last class • WATCH THE DEMO IN VIDEO 12 or Today’s class COMP 446 / ELEC 446 - Week 8

  22. Week 9 • CS193p Assignment #6 (partial) • Assignment #6 due 10/20/2011. • Optional parts due anytime before last day of classes. Required for a chance to get an A+ • Videos Optional from this point on • See Syllabus for Video suggestions • You will receive feedback on Final Project and Assignment #5 • Main activity after Assignment #6 is final project COMP 446 / ELEC 446 - Week 8

More Related