Created
January 2, 2015 16:05
-
-
Save danielctull/f5bc4e8ede964478e37c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @import Foundation; | |
| typedef void(^DCTAuthPlatformCompletion)(BOOL success); | |
| typedef void(^DCTAuthPlatformURLOpener)(NSURL *URL, DCTAuthPlatformCompletion completion); | |
| typedef void(^DCTAuthPlatformExpirationHandler)(); | |
| typedef id(^DCTAuthPlatformBeginBackgroundTaskBlock)(DCTAuthPlatformExpirationHandler expirationHandler); | |
| typedef void(^DCTAuthPlatformEndBackgroundTaskBlock)(id identifier); | |
| @interface DCTAuthPlatform : NSObject | |
| + (instancetype)sharedPlatform; | |
| @property (nonatomic, copy) DCTAuthPlatformURLOpener URLOpener; | |
| @property (nonatomic, copy) DCTAuthPlatformBeginBackgroundTaskBlock beginBackgroundTaskHandler; | |
| @property (nonatomic, copy) DCTAuthPlatformEndBackgroundTaskBlock endBackgroundTaskHandler; | |
| - (void)openURL:(NSURL *)URL completion:(DCTAuthPlatformCompletion)completion; | |
| - (id)beginBackgroundTaskWithExpirationHandler:(DCTAuthPlatformExpirationHandler)handler; | |
| - (void)endBackgroundTask:(id)identifier; | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @implementation DCTAuthPlatform | |
| + (instancetype)sharedPlatform { | |
| static DCTAuthPlatform *platform; | |
| static dispatch_once_t onceToken; | |
| dispatch_once(&onceToken, ^{ | |
| platform = [self new]; | |
| }); | |
| return platform; | |
| } | |
| - (void)openURL:(NSURL *)URL completion:(DCTAuthPlatformCompletion)completion { | |
| if (!completion) { | |
| completion = ^(BOOL success) {}; | |
| } | |
| if (!self.URLOpener) { | |
| completion(NO); | |
| return; | |
| } | |
| self.URLOpener(URL, completion); | |
| } | |
| - (id)beginBackgroundTaskWithExpirationHandler:(DCTAuthPlatformExpirationHandler)handler { | |
| if (!self.beginBackgroundTaskHandler) { | |
| return nil; | |
| } | |
| return self.beginBackgroundTaskHandler(handler); | |
| } | |
| - (void)endBackgroundTask:(id)identifier { | |
| if (!self.endBackgroundTaskHandler) { | |
| return; | |
| } | |
| self.endBackgroundTaskHandler(identifier); | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment