I am fetching some system information e.g. processor name processor cores and many more and then showing them on NSTextFeild.
The issue is for the time the information is getting fetched, the application hangs.
So, I want to run the task asynchronously.
Note: I have just started with cocoa so please do describe your solution. pretty please..
thanks in advance.
Your UI hangs because you are doing work on the main thread. Hence this is a thread problem. You can then run that fetch for information on another thread, a background thread that doesn't interact with the UI, display something to the user that the data is currently getting retrieved and then, when the data is ready, display it in your NSTextField.
Read more
Understanding dispatch_async
https://developer.apple.com/library/ios/documentation/Performance/Reference/GCD_libdispatch_Ref/
Related
I'm using GPUImageFilter in a chain, and most of the time it works OK. I've recently come across a few random crashes that match the symptoms in this github issue (albeit I'm using GPUImageFilter not live capture or video). I'm trying to find a suitable method that can ensure I've cleared the frame buffer and any other GPUImage-related activities in willResignActive.
Currently I have:
[[GPUImageContext sharedFramebufferCache] purgeAllUnassignedFramebuffers];
Is this sufficient? Should I use something else instead/in addition to?
As indicated there, seeing gpus_ReturnNotPermittedKillClient in a stack trace almost always is due to OpenGL ES operations being performed while your application is in the background or is just about to go to the background.
To deal with this, you need to guarantee that all GPUImage-related work is finished before your application heads to the background. You'll want to listen for delegate notifications that your application is heading to the background, and make sure all processing is complete before that delegate callback exits. The suggestion there by henryl is one way to ensure this. Add the following near the end of your delegate callback:
runSynchronouslyOnVideoProcessingQueue(^{
// Do some operation
});
What that will do is inject a synchronous block into the video processing pipeline (which runs on a background queue). Your delegate callback will block the main thread at that point until this block has a chance to execute, guaranteeing that all processing blocks before it have finished. That will make sure all pending operations are done (assuming you don't add new ones) before your application heads to the background.
There is a slight chance of this introducing a deadlock in your application, but I don't think any of my code in the processing pipeline calls back into the main queue. You might want to watch out for that, because if I do still have something in there that does that, this will lock your application. That internal code would need to be fixed if so.
Is there any way to run some activity after a Windows Store app has been installed?
I'd like to get some data from a webservice (data is rarely changes), but I would not like to make the query on the first start, because it might take some time, and I don't want to ruin the user experience.
Thanks!
You can have it run on a separate background thread while concurrently running the main thread. You can allocate limited resources to this separate background thread, then have it subside on it's own.
You can do an async operation as well from your app, see link from MSDN:
http://msdn.microsoft.com/en-us/library/windows/apps/br230301.aspx#AsyncOps
My codeSHOW app loads data asynchronously when it first starts, and stores the async promise as an app level variable so anything else in the app can await it. It's not exactly what you're looking for, but if it helps, it's available at http://codeshow.codeplex.com.
When my application loads, using the didFinishLaunchingWithOptionsi parse data from the internet to nsarrays. My question is, when the user exists the application by using the 'home' button, and then loads the application again how can the data be re-loaded? (because if the data does not reload - if there are any updates on websites, the new updates will not be seen).
Add an applicationWillEnterForeground method to your app delegate. Load the data there, or start a thread to load it if you like.
You should probably also periodically check for new data even while the app remains open, because the user could go idle for a long time.
As an aside, you shouldn't do anything which might block in applicationDidFinishLaunchingWithOptions. If you are using synchronous NSURLConnection APIs there is a danger the OS might kill your app for taking too long to launch. Best to either use the asynchronous/NSURLConnectionDelegate APIs or do the networking on a background thread and call back to the main thread when you need to update UI (UIKit does NOT like being called from background threads, as it is not thread safe. It might appear to work sometimes, but it will come back to bite you sooner or later).
I wanted to make an http call when my application is running in the background where i am trying to download multiple files. Is it possible to achieve this task. If available can anyone provide me with a sample code.
Thanks in advance.
Once the application is in the background it will usually be suspended. So you will not be able to download data continuously in the background.
If your task is limited you could try implementing beginBackgroundTaskWithExpirationHandler:. This will allow you to ask the system for extra time to perform the remainder of the task in the background.
You can take a look at the documentation provided by Apple to further understand how it is done.
Executing Code in the Background
Using the iPhone and objective C, is there a way to stall or perform a timing loop to allow for the GPS to catch up and return a valid set of coordinates?
Currently, the application runs too quickly and the GPS cannot supply the coordinates fast enough...
Since you said you're on iPhone, you're using CLLocationManager. Just set a delegate on the manager and wait for the locationManager:didUpdateToLocation:fromLocation: message to know when the GPS data is ready.
Assuming your GPS polling is running in a different thread to the User Interface, you can call the static NSThread functions sleepForTimeInterval or sleepUntilDate from the thread that is waiting for the GPS data.
If your mobile application is using GPS, your application should be prepared for location updates, even if your application doesn't track movements..
A common case would be where the user put your application in background and activate it later on a completely different location.
On iOS, create an implementation of CLLocationManagerDelegate like Anomie wrote. And use the timestamp of the update to evaluate the freshness of the location.
Don't sleep & poll like other people suggested.
Either block to wait for data or don't update anything if no data received. There is of course usleep(), but without showing code and specifically how your loop is executed and by what mechanism (threaded or not) we can only answer in general terms.