Calling method in background to get Facebook notifications and Twitter mentions - iphone

I want to call a method in background to check for new notifications and mentions for Facebook and Twitter. How can I do this ? Currently I am calling methods on view will appear of main view only. If any notifications will be there then I have to show badge count also.Shall I use NSThread For this purpose . I am not very much aware about NSThreads.
Please help
Thanks..

You can use NSOperationQueue for your requirment. Which executes set of NSOperation objects concurrently. And Implement a delegate method to update badge.
http://developer.apple.com/library/ios/#documentation/General/Conceptual/ConcurrencyProgrammingGuide/OperationObjects/OperationObjects.html#//apple_ref/doc/uid/TP40008091-CH101-SW1

Related

How do I tie up appDelegate to the rest of the app?

I am a relative beginner to iOS development, but I managed to get my app to do everything I want it to. However, I have some questions about tying the app up together.
The only code I have currently inside my appDelegate handles remote notifications; when I receive a remote notification I send out the alerts, messages, and so on to the user. I also generate notifications for the notification center which cause different methods to run inside different view controllers.
What about all the different functions in the appDelegate? DidEnterBackground, WillEnterForeground, etc.? My app starts on one view (view1), which creates an object (stream1), which has a method stopStream. I have buttons to start and stop the streams ([self.stream1 stopStream]). My question in, how do I call these methods to stop that particular instance of the object in one of the appDelegate methods? Do I need to create a notification for the notification center inside the appDelegate, and handle it triggering in the view? Or is there a simpler method? Or am I doing things completely wrong and not according to best practices?
Any help would be appreciated! Also a link to a guide about the architecture of apps, or a link to your favorite book about building apps in iOS would be great!
Your app delegate only needs to implement the various app delegate methods if the app delegate actually needs to do something with those events.
If a given view controller or other class is interested in the various app delegate notifications (such as enter background, or return to foreground, etc.), then the view controller or other class should register for the corresponding notification. See the docs for UIApplication for the different notifications.
Do not have the app delegate method post a custom notification.
All the methods you're looking for can be found listed here in the docs.
As for what to do about them thats definitely up to your app. It is best practice to handle at least going in and out of the background properly so at least use the methods for those and take the appropriate action in your app.
Its very common for apps to simply blast out NSNotifications like you mention. Its perfectly acceptable in most circumstances.

UIWebView loadRequest when applicationDidEnterBackground

In my app from applicationDidEnterBackground i want to ask the application for more time to
create a UIWebView and load request with UIBackgroundTaskIdentifier, then in the delegate
method of UIWebView (webViewDidFinishLoad) i want to do a stuff there and show an alert or
notification while the
application is still reining in the background .
so how i can do that?.
Apple's documentation for UIApplication class for beginBackgroundTaskWithExpirationHandler: method says:
You can call this method at any point in your application’s execution.
You may also call this method multiple times to mark the beginning of
several background tasks that run in parallel. However, each task must
be ended separately. You identify a given task using the value
returned by this method.
This method can be safely called on a non-main thread.
So, once web view finish loading in background you can trigger another operation from webViewDidFinishLoad to show alert.
When you receive applicationDidEneterBackground your app is already effectively in the background. At that moment all your networking should be closed and you really shouldn't try to show any alerts or notifications.

iPhone: Background Listener

Is there any background listener in iPhone SDK ? Which I can register in viewDidLoad and unregister in viewDIdUnload...A listener, that I can say something to do at any time ? Thanks...
Take a look at NSNotification and NSNotificationCenter. You can also do Key Value Observing to make functions that respond to variable changes.

iOS-FBConnect - requests results crash the app if the delegate of them released

I'm developing an iOS app and views create a request for their data,
now if the user dismiss the view, it's released and when the FBConnect call:
if ([_delegate respondsToSelector:
#selector(request:didReceiveResponse:)]) {
[_delegate request:self didReceiveResponse:httpResponse];
}
the app is crashed...
Any solution for that case?
Thanks!
Try using a higher-level controller as delegate, e.g. the main view controller, or the app delegate itself. This way you will always be sure that that component will not be released while the app is running.
either retain the _delegate. Or release the caller (the one making requests) as well from _delegate's dealloc method.
Or if both the above solutions are not suitable, then put the protocol implementation somewhere else.If you post more details may be then people will be able to provide specific answer.

How do I get notified when a user opens my iPhone app while in a phone call?

I need to adjust several views in the event that a user visits my app while in a phone call. Is there a best practice for being notified of this?
Thanks!
You want to check the statusBarFrame property of the shared UIApplication instance. Take a look at Resize for in-call status bar?.