0

I'm trying to hook into the UIActivityViewController as I need to stop some code from running whilst the view is open.

When the view is closed, I need to start my class again.

UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[activityController setTitle:code];
[activityController setExcludedActivityTypes:self.excludedItems];
[activityController setCompletionHandler:^(NSString *activityType, BOOL completed) {
    self.label.text = @"Scanning...";
    [self.qrScannerView start];
}];

And when it's opened, I need to stop it:

[self presentViewController:activityController animated:YES completion:^{
    [self.qrScannerView stop];
}];

This seems to work once, but afterwards it'll continue to do run. What am I doing wrong?

James
  • 5,137
  • 5
  • 40
  • 80
  • Maybe something to do with the reference to `self` in the block? http://stackoverflow.com/questions/21113963/is-the-weakself-strongself-dance-really-necessary-when-referencing-self-inside-a – Sam Jarman Jan 21 '14 at 21:59
  • Ah. I figured it out. My `start` and `stop` events would only fire if `_canScan` was the right bool value. It seems they were being set back quicker than the completions. – James Jan 21 '14 at 22:11

1 Answers1

0

This was caused by my custom class changing the values of stopped and started too soon, so I could never close.

James
  • 5,137
  • 5
  • 40
  • 80