How can I check missed call in iPhone using Objective-C?
There is no access to the iPhone phone from third party software. Luckily.
The sandbox prevents access to the phone functions from third-party apps. Thus there is no way to detect missed calls.
Using Core Telephony framework, detect for call state changes.
Listen for incoming calls. Now your application will be notified when there is an incoming call.
After this, when the alert pops up, applicationWillResignActive is called.
If the user accepts the call, applicationDidEnterBackground is called, and then when user switches back to your application applicationDidBecomeActive will be called.
If the user rejects the call or the calling person ends the call before accept/reject, applicationDidBecomeActive will be called.
The second case indicates a missed call.
When you have an incoming call, the function
- (void)applicationWillResignActive:(UIApplication *)application;
is called and if the call gets missed, the application will be active again and the function
- (void)applicationDidBecomeActive:(UIApplication *)application;
is called.
This way, you can detect missed calls. There is no other method to do this that i am aware of.
The only drawback is that these methods are also called when you Lock/Unlock the device when your application is active so you will not be able to know whether it was a missed call or the user locked the device.
Related
Is it bad practice to call registerForRemoteNotificationTypes in applicationDidBecomeActive? I was calling it in applicationDidFinishLoading, but with multitasking, the registration was not happening for days to weeks for some users.
I'd like to call the registration more often, but don't want to call it this often if it's bad practice.
It is not bad practice.
In fact Apple documentation says this: Apple documentation
If your application has previously registered, calling
registerForRemoteNotificationTypes: results in iOS passing the device
token to the delegate immediately without incurring additional
overhead.
Device tokens can change.
Your app needs to reregister every time it is launched in iOS by
calling the registerForRemoteNotificationTypes: method of
UIApplication.
Based on Local and Push Notification Programming Guide
I'm developing for a jailbroken device, and I want to create an app that detects a phone call, and presents an alert on top of the call screen. How can I achieve this? What hidden frameworks should I use?
Within CoreTelephony is the CTCallCenter class which includes the callEventHandler property, which is a block that runs upon changes in the call state. As described in the documentation, you could use this to become notified of these states:
CTCallStateDialing;
CTCallStateIncoming;
CTCallStateConnected;
CTCallStateDisconnected;
Docs say you must be in active app state. If you are suspended, then you only get one block state change notification upon waking up. If you are jailbroken and in background state, hopefully you would get your block executed, so you could become aware of this.
This question already has an answer here:
Closed 11 years ago.
Possible Duplicate:
how can i terminate api call in iphone
hi friends,
I have an api call in my iphone app. That api call take more time for loading (near 100 sec). while the api processing, i hit the home button of my app. the app terminated. but the api call doesn't terminated.
how can I terminate api call.
Like e.James said, look at the UIApplicationDelegate protocol.
However, you might be more interested in either applicationDidEnterBackground: or
applicationWillTerminate: (depending on whether or not the device supports multitasking), because applicationWillResignActive: will also be called in cases like when the user receives a phone call, or other similar interruptions (see documentation).
Check out the UIApplicationDelegate protocol. You can cancel the API call in the applicationWillResignActive: method, which is called just before the app goes into background mode.
Seeing you duped the question, i'll post my answer here too:
I suppose you mean a web API call, like google's geoservices. To do this, you will need to make the call using a NSURLConnection. This way, you can cancel a call anytime using [connection cancel].
Try this tutorial. It's meant for a JSON api call. If you need another API, just start reading from 'fetching JSON over HTTP', there they set up a NSURLConnection. If you retain this connection until it's done, you will be able to make the [connection cancel] call at anytime.
Using the UIApplicationDelegate, you can detect the app entering the background.
I would like a local notification to be fired when a call is received (and to show an alert) - is this possible? Can a call event get an app to launch or a notification to be fired?
How is skype fired? With push notifications?
Thanks
Your application delegate will receive calls to various UIApplicationDelegate protocol methods when various events happen. One of these is the - (void)applicationWillResignActive:(UIApplication *)application method, which is called for incoming calls or text messages, but could be called for other reasons as well.
See the UIApplicationDelegate protocol reference for more information.
If your application is running while a call is in place check out the CoreTelephony Framework. The CTCall class provides information about the call state. I have not used this myself but you may find it useful.
extern NSString const *CTCallStateDialing;
extern NSString const *CTCallStateIncoming;
extern NSString const *CTCallStateConnected;
extern NSString const *CTCallStateDisconnected;
Edit:
The CTCallCenter allows you to register for call event state changes. As I said before your application will need to be running to know that something has changed. You may want to request the maximum backgrounding time (I think it is 10 minutes now) when your application is moved to the background. These api's are only available in iOS 4.0 and later.
And, to answer the part of your question nobody's touched yet, Skype is using backgrounding methods specifically meant to keep an app alive in the background to receive VOIP calls. A little bit of it is actually running, waiting to be called. Unless you claim to be a backgrounding app for VOIP or audio purposes, you can't do that--and if you DO claim that, you better be DOING it, or you'll never hit the app store.
The best you can do is hook the applicationWillResignActive method, which gets called basically whenever your app loses focus (which happens when a call comes in, but also happens for other reasons, so it's not perfect).
See: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html
If the user received a call during application running, how to automatically open the application after call ended. And how to restore the last session, so that the user would not start from the beginning?
Thanks
You need to implement the following methods from the UIApplicationDelegate protocol:
applicationWillResignActive is called when the phone receives an incoming call
applicationWillTerminate is called when the user answers the call
applicationDidBecomeActive is called if the user choose not to answer the call
applicationWillTerminate will give a few seconds to save your apps current state. The easiest way to save state is through the NSUserDefaults class. When the app starts again you read your state from NSUserDefaults and restore the app to its previous state.