Let's assume that I have a GDC thread running when the app goes inti suspended mode. What will happen? Will the tread stop or continue running? Or do I have to stop it myself, in that case how is this done?
Thankful for advice!
Background State & NSThread
The system automatically suspends all threads include GCD threads.
Related
I have some background threads in my app where I have some NSTimers running in NSDefaultRunLoopMode mode. When I press home button the app goes to background.
If I don't call beginBackgroundTaskWithExpirationHandler: in applicationDidEnterBackground: the threads get suspended when the application is in background. But if I call beginBackgroundTaskWithExpirationHandler: the threads don't get suspended even after the expiration handler returns.
Why is it that background threads keep running in one case while in another case they don't? When will the background threads get suspended in the second case?
According this document beginBackgroundTaskWithExpirationHandler:
This method lets your app continue to run for a period of time after it transitions to the background.
That why if you call beginBackgroundTaskWithExpirationHandler: in applicationDidEnterBackground: the threads don't get suspended.
And
Each call to this method must be balanced by a matching call to the endBackgroundTask: method. Apps running background tasks have a finite amount of time in which to run them. (You can find out how much time is available using the backgroundTimeRemaining property.) If you do not call endBackgroundTask: for each task before time expires, the system kills the app. If you provide a block object in the handler parameter, the system calls your handler before time expires to give you a chance to end the task.
So the background threads get suspended in the second case when you use beginBackgroundTaskWithExpirationHandler: right way with endBackgroundTask: by adding endBackgroundTask: outside of expiration handler.
In my ios app, I start listening user's location updates in the background for a while (up to 15 mins) when I receive background fetch execution. However, after I stop updates, the app crashes with the 0x8badf00d error.
I've enabled background location and background fetch permissions, and I also have enabled background location updates on CLLocationManager.
Any idea on why this error happens?
The problem isn’t that it isn’t running in the background, but rather whatever was running was blocking the main thread.
The 0x8badf00d (“ate bad food”; lol) indicates that the watchdog process (that monitors for dead/blocked processes) killed your app, generally because you did something to block the main thread. If you avoid blocking the main thread, this error should go away. See Technical Note 2151: Understanding and Analyzing Application Crash Reports and search for 0x8badf00d.
As it says:
The exception code 0x8badf00d indicates that an application has been terminated by iOS because a watchdog timeout occurred. The application took too long to launch, terminate, or respond to system events. One common cause of this is doing synchronous networking on the main thread. Whatever operation is on Thread 0 needs to be moved to a background thread, or processed differently, so that it does not block the main thread.
They’re focusing on synchronous network requests, but it can be anything that blocked the main thread for too long, whether a slow synchronous process or a deadlock or whatever. You should look at the stack trace for thread 0 and see if you can identify what blocked the main thread. There’s not enough here for us to diagnose it, though.
Common culprits include synchronous network calls, synchronous GCD calls, inappropriate use of semaphores, locks, or dispatch group “wait” calls, deadlocks, etc.
My app while in background receive pushes to trigger some background tasks, scheduled in a NSOperationQueue.
The first NSOperation terminates correctly, but the second doesn't terminate, it seems like the task is paused, and when I put the app back in foreground the operation can terminate like it should.
Is there restrictions for background tasks ? (The tasks take about 2 or 3 seconds to execute)
Thank you
you have enable any of the background service like Location , Background fetch , Remote Notification to enable active your app in background mode. Please below apple link where you may get more idea -
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
PushSharp only processes the queue when stop is called. Does anyone have an idea how often push sharp will process the queue or flush it? I don't want to have to call stop and start every time I want to send a notification to conserve resources.
pushService = new PushService();
pushService.StartApplePushService(new ApplePushChannelSettings(prod, cert.InputStream.ReadToEnd(), passConfig.Value));
pushService.QueueNotification(
NotificationFactory.Apple().ForDeviceToken("mydeviceid").WithAlert("Notifications Started!").WithSound("default").WithBadge(7));
pushService.StopAllServices(true);
I'm a complete and utter idiot...
The main thread was completing execution before the queue timer could process the notification. StopAllServices forced the thread to wait... Maybe this will help someone else.
I'm debugging a background task issue where my app is being killed by the watchdog when socket data is received too often in the background.
Does the watchdog perform it's operations under the context of a debugger?
My answer is: I do not believe so.
Based on some logs I have seen about apps failing to respond for 10 seconds while paused in the debugger, I would say yes it is watching, but it does not enforce its rules. It simply informs you.