Skip to content

Commit

Permalink
Update Book Registry Sync to include necessary callbacks for the
Browse files Browse the repository at this point in the history
Background Fetch delegate.
  • Loading branch information
gioneill committed Jan 8, 2019
1 parent 1fd61fe commit cdae4e6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
9 changes: 3 additions & 6 deletions Simplified/NYPLAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,11 @@ - (BOOL)application:(__attribute__((unused)) UIApplication *)application
}

- (void)application:(__attribute__((unused)) UIApplication *)application
performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))backgroundFetchHandler
{
// Only the current Library Account will perform background fetches.
[[NYPLBookRegistry sharedRegistry] syncWithCompletionHandler:^(BOOL __unused success) {
//GODO this block is not being called in a lot of places. come back to this.
//GODO is a sync being called anywhere else when the app launches?
completionHandler(UIBackgroundFetchResultNewData);
}];
[[NYPLBookRegistry sharedRegistry] syncWithCompletionHandler:nil
backgroundFetchHandler:backgroundFetchHandler];
}

- (BOOL)application:(__attribute__((unused)) UIApplication *)application handleOpenURL:(NSURL *)url
Expand Down
4 changes: 4 additions & 0 deletions Simplified/NYPLBookRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ static NSString *const NYPLBookProcessingDidChangeNotification =
// not to be called.
- (void)syncWithCompletionHandler:(void (^)(BOOL success))handler;

// Calls `syncWithCompletionHandler` including required callbacks for the Background Fetch delegate.
- (void)syncWithCompletionHandler:(void (^)(BOOL success))handler
backgroundFetchHandler:(void (^)(UIBackgroundFetchResult))fetchResult;

// Calls syncWithCompletionHandler: with a handler that presents standard success/failure alerts on
// completion.
- (void)syncWithStandardAlertsOnCompletion;
Expand Down
11 changes: 11 additions & 0 deletions Simplified/NYPLBookRegistry.m
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,21 @@ - (void)justLoad
}

- (void)syncWithCompletionHandler:(void (^)(BOOL success))handler
{
[self syncWithCompletionHandler:handler backgroundFetchHandler:nil];
}

- (void)syncWithCompletionHandler:(void (^)(BOOL success))handler
backgroundFetchHandler:(void (^)(UIBackgroundFetchResult))fetchResult
{
@synchronized(self) {
if(self.syncing) {
fetchResult(UIBackgroundFetchResultNoData);
return;
} else if (![[NYPLAccount sharedAccount] hasBarcodeAndPIN]) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
if(handler) handler(NO);
fetchResult(UIBackgroundFetchResultNoData);
}];
return;
} else {
Expand All @@ -288,6 +296,7 @@ - (void)syncWithCompletionHandler:(void (^)(BOOL success))handler
[[NSOperationQueue mainQueue]
addOperationWithBlock:^{
if(handler) handler(NO);
fetchResult(UIBackgroundFetchResultFailed);
}];
return;
}
Expand All @@ -296,6 +305,7 @@ - (void)syncWithCompletionHandler:(void (^)(BOOL success))handler
// A reset must have occurred.
self.syncing = NO;
[self broadcastChange];
fetchResult(UIBackgroundFetchResultNoData);
return;
}

Expand Down Expand Up @@ -338,6 +348,7 @@ - (void)syncWithCompletionHandler:(void (^)(BOOL success))handler
[[NSOperationQueue mainQueue]
addOperationWithBlock:^{
if(handler) handler(YES);
fetchResult(UIBackgroundFetchResultNewData);
}];
};

Expand Down
11 changes: 0 additions & 11 deletions Simplified/NYPLUserNotifications.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@ let DefaultActionIdentifier = "UNNotificationDefaultActionIdentifier"
}
}

/* Just a proposal for now...
if #available(iOS 12.0, *) {
//GODO TODO i'm not convinced "provisional" is the UX we want. come back to this
unCenter.requestAuthorization(options: [.provisional,.badge,.sound,.alert]) { (granted, error) in
if granted {
Log.info(#file, "Full Notification Authorization granted.")
}
}
}
**/

/// Create a local notification if a book has moved from the "holds queue" to
/// the "reserved queue", and is available for the patron to checkout.
class func compareAvailability(cachedRecord:NYPLBookRegistryRecord, andNewBook newBook:NYPLBook)
Expand Down

0 comments on commit cdae4e6

Please sign in to comment.