cs193p – Assignment #6 Part #4

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

Leave a Reply

Your email address will not be published.