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.
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.
As in my application if some action regarding "httpcall" are posted in the mainthread and my app is waiting for a response from server and same time home button is pressed than although app is entering background but IOS delegates (such as "didEnterBackground") are not getting called till the response are received.
Also sometime even if I'm relaunching the app its not responding till it gets crashed by itself.
Note:I'm using CyberLink code for my HTTP posts.
As Apple says :
You should use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. You should also disable updates to your application’s user interface and avoid using some types of shared system resources (such as the user’s contacts database)
I think you try to do something in background, for which didEnterBackground is not enough. Use Grand Central Dispach istead.
Since your Http method are of synchronous type ..Your UI will froze till response.
What you have done is in simple words tell the OS to perform these http requests before doing anything else.
On pressing home the system will wait..for a few seconds to receive a response..otherwise it will quit thee app. since it violates app guidelines..(you are blocking OS indefinitely)
The didEnterBackground will be called only if these requests will be finished or will not be called in the case when OS decides to terminate your app.
I have an iPhone app that uses ASIHTTPRequest to transmit data input by the user to a remote MySQL database via a PHP webservice layer. This works perfectly.
If the user presses the submit button the data should be sent regardless...the problem arises when there is insufficient bandwidth...rather than displaying some uialert to inform the user, I would like to implement some kind of function that constantly 'sniffs' for an internet connection even when the app isn't running (in main view) that ensures that the user only has to press 'submit' once.
How is this possible? Has anyone come across any tutorials/examples of anything similar?
Check out this example application from Apple: Reachability
It'll help you with some code to detect when the connection has changed.
Here's a link about backgrounding tasks. As you'll read, you can request additional time to complete a task, but it won't wait an infinite amount of time until it's complete. Background Tasks
Use the Reachability API in conjunction with a flag of some sort that will perform the desired action once it detects that a connection is available.
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 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