Skip to content
This repository was archived by the owner on Jun 14, 2024. It is now read-only.

Commit f568e5e

Browse files
committed
[ios] Fixes an issue that caused a timer run in a background thread.
1 parent 4dbe089 commit f568e5e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Examples/ObjectiveC/AnimatedLineExample.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,13 @@ - (void)animatePolyline {
5959
self.currentIndex = 1;
6060

6161
// Start a timer that will simulate adding points to our polyline. This could also represent coordinates being added to our polyline from another source, such as a CLLocationManagerDelegate.
62-
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(tick:) userInfo:nil repeats:YES];
62+
self.timer = [NSTimer timerWithTimeInterval:0.05 target:self selector:@selector(tick:) userInfo:nil repeats:YES];
63+
[[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
6364
}
6465

6566
- (void)tick:(NSTimer*)timer {
67+
NSAssert([[NSThread currentThread] isMainThread], @"%s must be accessed on the main thread, not %@", __PRETTY_FUNCTION__, [NSThread currentThread]);
68+
6669
if (self.currentIndex > self.locations.count) {
6770
[self.timer invalidate];
6871
return;

0 commit comments

Comments
 (0)