Skip to content

Instantly share code, notes, and snippets.

@julianjames
Last active August 29, 2015 14:20
Show Gist options
  • Save julianjames/4784865ddc6ecfceb7ee to your computer and use it in GitHub Desktop.
Save julianjames/4784865ddc6ecfceb7ee to your computer and use it in GitHub Desktop.
- (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