Skip to content

Commit

Permalink
Issue Simperium#216: Updating Simperium API
Browse files Browse the repository at this point in the history
  • Loading branch information
jleandroperez committed Nov 29, 2013
1 parent 1522a5a commit 0e3faa2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Simperium/Simperium.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
@class NSWindow;
#endif

extern NSString * const SimperiumWillSaveNotification;


#pragma mark ====================================================================================
#pragma mark SimperiumDelegate
#pragma mark ====================================================================================
Expand Down Expand Up @@ -88,7 +91,7 @@ typedef void (^SimperiumForceSyncCompletion)(BOOL success);

#if !TARGET_OS_IPHONE
// Support for OSX delayed app termination: Ensure local changes have a chance to fully save
- (void)replyAppTerminationWhenReady;
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
#endif

// Clears all locally stored data from the device. Can be used to perform a manual sign out.
Expand Down
20 changes: 18 additions & 2 deletions Simperium/Simperium.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@
#import "SPAuthenticationWindowController.h"
#endif

NSString * const UUID_KEY = @"SPUUIDKey";

#pragma mark ====================================================================================
#pragma mark Simperium: Constants
#pragma mark ====================================================================================

NSString * const UUID_KEY = @"SPUUIDKey";
NSString * const SimperiumWillSaveNotification = @"SimperiumWillSaveNotification";


#pragma mark ====================================================================================
Expand Down Expand Up @@ -532,7 +537,14 @@ - (BOOL)saveWithoutSyncing {

#if !TARGET_OS_IPHONE

- (void)replyAppTerminationWhenReady {
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {

// Post Notification: Allow the client app to perform last minute changes
[[NSNotificationCenter defaultCenter] postNotificationName:SimperiumWillSaveNotification object:self];

// Proceed Saving!
[self save];

// Dispatch a NO-OP on the processorQueue's: we need to wait until they're empty
dispatch_group_t group = dispatch_group_create();
for(SPBucket* bucket in self.buckets.allValues) {
Expand All @@ -543,6 +555,10 @@ - (void)replyAppTerminationWhenReady {
dispatch_group_notify(group, dispatch_get_main_queue(), ^ {
[[NSApplication sharedApplication] replyToApplicationShouldTerminate:YES];
});

// No matter what, delay App Termination:
// there's no warranty that the processor's queues will be empty, even if the mainMOC has no changes
return NSTerminateLater;
}

#endif
Expand Down

0 comments on commit 0e3faa2

Please sign in to comment.