Last active
August 29, 2015 14:20
-
-
Save julianjames/4784865ddc6ecfceb7ee 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
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest: | |
(NSDictionary *)userInfo reply:(void(^)(NSDictionary *replyInfo))reply { | |
__block UIBackgroundTaskIdentifier bgTask; | |
bgTask = [application beginBackgroundTaskWithName:@"MyTask" expirationHandler:^{ | |
[application endBackgroundTask:bgTask]; | |
bgTask = UIBackgroundTaskInvalid; | |
}]; | |
// Start the long-running task and return immediately. | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | |
// Do the work associated with the task, preferably in chunks. | |
NSString *state = ([BluetoothLEHelper getBluetoothLEState] == BluetoothLEStateReady) | |
? @"Connected!" : @"Not connected"; | |
NSArray *games = [Game sortedGames]; | |
NSMutableArray *gameDetails = [[NSMutableArray alloc] init]; | |
for (Game *game in games) | |
[gameDetails addObject: @{@"id" : game.id , @"name" : game.name}]; | |
reply(@{@"Ball State" : state , @"Games" : gameDetails}); | |
[application endBackgroundTask:bgTask]; | |
bgTask = UIBackgroundTaskInvalid; | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment