I have a background task that stop a streamer
after 30 minutes as follows:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
[[UIApplication sharedApplication] endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
while ([[NSDate date] timeIntervalSinceDate:[[NSUserDefaults standardUserDefaults]objectForKey:@"date"]]<30) {
NSLog(@"<30");
[NSThread sleepForTimeInterval:1];
}
NSLog(@"Stop");
[main stopStreaming];
});
}
but the problem is when the user Did Enter Background the bgTask called again, thats mean if the user entered the background 10 times he will have 10 back ground UIBackgroundTaskIdentifier
That cause the streamer playing badly and the NSLog(@"<30");
get called more than one time at the same second.
Please Advice.