cs193p – Assignment #6 Part #10

Please note, this blog entry is from a previous course. You might want to check out the current one.

Assignment #6 Task #5

All of your table views everywhere in your application (including the Recents tab) must be driven by Core Data (i.e. not NSUserDefaults nor Flickr dictionaries). You no longer have to support “pulling down to refresh” (though see Extra Credit 1).

To handle the recent entity of the database schema, create another category, containing a single class method:

+ (Recent *)recentPhoto:(Photo *)photo;

Continue reading “cs193p – Assignment #6 Part #10”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #6 Part #9

Please note, this blog entry is from a previous course. You might want to check out the current one.

Photos Table & Image View

Assignment #6 Task #4

When a region is chosen, all the photos in your database that were taken in that region should be displayed (no sections are required). When a photo is then chosen, it should be displayed in the same way photos were displayed in last week’s assignment.

Like in the last part, clear out the generic photo-table-view controller. For now it needs only a single method to setup the table cells using the photo data:

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"Photo Cell"];
    
    Photo *photo = [self.fetchedResultsController objectAtIndexPath:indexPath];
    cell.textLabel.text = photo.title;
    cell.detailTextLabel.text = photo.subtitle;
    
    return cell;
}

Continue reading “cs193p – Assignment #6 Part #9”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #6 Part #8

Please note, this blog entry is from a previous course. You might want to check out the current one.

Show Top Regions

Assignment #6 Task #1

Your application must work identically to last week except that where you are displaying the “top places” (as reported by Flickr), you are going to display the “top regions” in which photos have been taken. You will calculate the most popular regions from the data you gather periodically from the URLforRecentGeoreferencedPhotos.

Now it’s time to connect the database with the view of the app. Start by renaming the top-places view controllers. Select and right click the class name, choose Refactor -> Rename…. Change the name and keep “Rename related files” checked. This will affect the header and source file of that class as well as both story boards.

Repeat those steps with the place view controller.
Continue reading “cs193p – Assignment #6 Part #8”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #6 Part #7

Please note, this blog entry is from a previous course. You might want to check out the current one.

Download and Store Region Information

Hint #12

To get the name of a place’s region from a place_id, you will need to query Flickr again at the URLforInformationAboutPlace: (off the main queue, of course) using the FLICKR_PHOTO_PLACE_ID found in a photo dictionary and then pass the dictionary returned from that (converted from JSON) to extractRegionNameFromPlaceInformation:.

After we have stored the photo data, lets fetch and store the region data:

+ (void)loadPhotosFromFlickrArray:(NSArray *)photos // of Flickr NSDictionary
         intoManagedObjectContext:(NSManagedObjectContext *)context
{
    ...
    [Region loadRegionNamesFromFlickrIntoManagedObjectContext:context];
}

Continue reading “cs193p – Assignment #6 Part #7”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #6 Part #6

Please note, this blog entry is from a previous course. You might want to check out the current one.

We know already from task #7 that we need to store the photos using Core Data.

Assignment #6 Task #6

You must use UIManagedDocument to store all of your Core Data information. In other words, you cannot use the NSManagedObjectContext-creating code from the demo.


Use UIManagedDocument to Store Core Data

Hint #6

The fact that the UIManagedDocument opens/creates asynchronously has ramifications for your entire application design since its NSManagedObjectContext may not be ready the instant your application’s UI appears. Design your code as if it might take 10 seconds or more to open/create the document (meanwhile your UI is up, but empty, which is fine). It never will actually take that long, but your code should work if it did.

Continue reading “cs193p – Assignment #6 Part #6”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #6 Part #5

Please note, this blog entry is from a previous course. You might want to check out the current one.

Photo Downloads using Background Fetch

Assignment #6 Task #7

Fetch the URLforRecentGeoreferencedPhotos from Flickr periodically (a few times an hour when your application is in the foreground and whenever the system will allow when it is in the background using the background fetching API in iOS). You must load this data into a Core Data database with whatever schema you feel you need to do the rest of this assignment.


To set up a background fetch, you only need to tell the app what to do when it gets called while it is in the background. In our case: load photos. If the download works, do something with the photos then call the provided completion handler, letting it know that there is new data. If it fails call the completion handler and tell it that the download did not work:
Continue reading “cs193p – Assignment #6 Part #5”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #6 Part #4

Please note, this blog entry is from a previous course. You might want to check out the current one.

Trigger periodical Photo Downloads with App in the Foreground

Assignment #6 Task #7

Fetch the URLforRecentGeoreferencedPhotos from Flickr periodically (a few times an hour when your application is in the foreground and whenever the system will allow when it is in the background using the background fetching API in iOS). You must load this data into a Core Data database with whatever schema you feel you need to do the rest of this assignment.


We need a helper method which expands our Flickr fetch method with a timer attribute:

- (void)startFlickrFetch:(NSTimer *)timer
{
    [self startFlickrFetch];
}

… and – for now – schedule repeating calls of this method:

#define FOREGROUND_FLICKR_FETCH_INTERVAL (15 * 60)

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self startFlickrFetch];
    [NSTimer scheduledTimerWithTimeInterval:FOREGROUND_FLICKR_FETCH_INTERVAL
                                     target:self
                                   selector:@selector(startFlickrFetch:)
                                   userInfo:nil
                                    repeats:YES];    
    return YES;
}

To see if this working, you might want to reduce the fetch interval, e.g. 30 seconds …

The complete code for tasks #1 to #7 is available on github.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail