Advertisement
Guest User

Untitled

a guest
Jul 14th, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. - (id)initWithConnectDevice:(ConnectDevice *)cDevice toPeripheral:(CBPeripheral*)peripheral oPerationIndex:(int) index{
  2.  
  3. if (self = [super init]) {
  4.  
  5. operationIndex = index;
  6. executing = NO;
  7. finished = NO;
  8. self.connectDevice = cDevice;
  9. [self.connectDevice setDelegate:self];
  10. self.connectedPeripheral = peripheral;
  11. }
  12. return self;
  13.  
  14. -(BOOL)isConcurrent{
  15. return YES;
  16. }
  17. - (BOOL)isExecuting {
  18. return executing;
  19. }
  20.  
  21. - (BOOL)isFinished {
  22. return finished;
  23. }
  24.  
  25. -(void) terminateOperation {
  26. [self willChangeValueForKey:@"isFinished"];
  27. [self willChangeValueForKey:@"isExecuting"];
  28. finished = YES;
  29. executing = NO;
  30. [self didChangeValueForKey:@"isExecuting"];
  31. [self didChangeValueForKey:@"isFinished"];
  32. }
  33.  
  34. - (void)start {
  35.  
  36. @autoreleasepool {
  37.  
  38. if (self.isCancelled){
  39.  
  40. [timer invalidate];
  41. [self willChangeValueForKey:@"isFinished"];
  42. finished = YES;
  43. [self didChangeValueForKey:@"isFinished"];
  44. return;
  45. }
  46.  
  47. timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerFired:) userInfo:nil repeats:YES];
  48. [[NSRunLoop currentRunLoop] run];
  49.  
  50. }
  51. }
  52.  
  53. -(void)timerFired:(id)sender{
  54.  
  55. NSLog(@"timerFired");
  56.  
  57. }
  58.  
  59. OperationQueue *queue = [[OperationQueue alloc] initWithConnectDevice:connectDevices toPeripheral:peripheral oPerationIndex:operationIndex];
  60. queue.delegate = self;
  61.  
  62. [[[AppDelegate app] mainQueue] addOperation:queue];
  63. operationIndex = operationIndex+1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement