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.
Related
Whats the correct approach for incoming calls on iOS. I use voip notification and e.g. when somebody is calling to me and I am not answering then after 30 sec I finish call and I send next voip notification (cancel notificaiton) to remove notification about call. The problem is that since iOS 13 we have to report all of voip notification. What should we do in this situation because I can't send voip notification (because I stop getting notification later due to apple politics) if somebody don't answer or when caller (outside of app) finish the call first then calle (app) have to get signal that call is terminated and to finish the call. How we should inform app that call is closed (if we answered or nope)? Maybe is there a way to report voip notification without opening callkit screen and terminating it automatically?
I think there are a couple of things that you can do here,
1/ I didn't understand why you are not able to use another VoIP to stop ringing, you should be able to do it. If there is already call kit presented in the system from your app you don't need to present another one, the system is smart enough to understand this and won't blacklist you. And in your case, since your phone is still ringing you should be able to send another VoIP without any problem, if this not working for you I suggest that, you should make sure you have an active call.
2/ You can create your own timeout mechanism, since app is awake and woke up with call kit OS won't terminate your app even if it is in background, so create your own GCD timeout or any other similar solution and use it.
3/ If you don't want to use VoIP at all, then you can use alert or background notifications however delivery is not guaranteed for these notifications, especially for background notifications.
I am new to iPhone. i have faced a new problem. I have an api interaction in my app. That api take long time for loading. when i terminate my app manually,while loading that api my app closed. Then i would open my app it will closed immediately.
can any one help me how can i terminate or kill the api call while cancel it.
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: http://mobileorchard.com/tutorial-json-over-http-on-the-iphone/ 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
I am editing some thing in an iPhone editor application. That time, I am getting a call. How can I identify an incoming call by coding ?
If any one having idea about this, just share with us.
You can't. This is actually a FAQ already :-) All you can do is implement the applicationWillResignActive method in your application delegate (or listen to the corresponding notification). However, you also get this event when some alerts are shown or when the screen gets locked and you can't distinguish why you are getting the event.
Take a look at following URL
Could be helpful for you
Core Telephony
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.