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

cs193p – Assignment #6 Part #3

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

Download Photos from Flickr using the background fetching API

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.


Task #7 requires to use the background fetching API instead of using ephemeral sessions like we did in part #2.

Add the background-fetching capability to your target:

cs193p – assignment #6 task #1 - add background fetch capability
add background fetch capability

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

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #6 Part #2

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

… back to the actual task … prevent the “old” top-places table view controller from loading photos we do not need any more:

- (void)viewDidLoad
{
    [super viewDidLoad];
//    [self fetchPlaces];
}

Download Photos from Flickr using URLforRecentGeoreferencedPhotos:

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.

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

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail