Is there a way to programatically check if the audio system is being exclusively used on the iPhone? If an app tries to use the audio system when a FaceTime or cellular phone call is active, it will get errors when trying to start up audio. I'd like to check if the audio system is being exclusively used before attempting to start up audio.
The app I'm working on is a VOIP type app. When there is an incoming call, I'd like to check if the audio system is usable before the call is allowed to be answered. I have tried CTCallCenter and it works for cell phone calls, but FaceTime calls don't show up in there.
Thanks,
Conway
Couldn't you initialize the audio input as soon as the incoming call is detected and start the queue once the user accepts the call?
Look at the interruption handling delegates in the audio session documentation.
https://developer.apple.com/Library/ios/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Introduction/Introduction.html
You can set a flag in your app to prevent answering of your voice call if you are between beginInterruption and endInterruption methods.
Related
I have a piece of code wherein I make a server call and based on the response I play a sound. Now, this does not work when my application is in background or my devicei is locked.
Is there any way we can execute this piece of code (Server call and response handling) even if app is in background or device is locked?
There is no general solution, which is by design. (Apple does not want you to have a potentially CPU- and power-intensive process running in the background and degrading user experience.)
There are a few limited-case options available:
You said you want to play a sound. If by this you mean "play music" or some such streaming, there is an audio background task that your application can register to perform. Note that you must actually be streaming audio; Apple rightfully frowns upon apps that try to use this approach to circumvent the general-case prohibition and will reject your App Store submission accordingly.
You can invert your scenario and have the server send a push notification through the Apple Push Notification service. Depending on the user's settings, an alert, badge, or sound can result. This might be the best fit for you if you aren't streaming audio.
If what you are really intending to do is, say, finish an upload or download (and the sound is a completion notification), you can request some additional time to finish that task after the app is nominally backgrounded or the device locked. Use -[UIApplication beginBackgroundTaskWithExpirationHandler:] from within the appropriate UIApplicationDelegate methods to register such a task. Note that you have a limited (but appreciable) amount of time to finish your task, and I don't think you can play media in this mode.
I am at the beginning with RestKit-development. I develop an app that
get data from a Server and map these in objects. With a trick of
silence music, is it possible to send request to the backend, if the
app is in background mode . If I
leave the app the request will send, but the delegate of "finish with
objectmapping" will not throw, but if I start (activate the app) the
app, the delegates
will fire. Is there are a way, to map the json if the app is in
background mode?
I've provided an answer to your other post which I think will help you here. See link:
Your other post
Yes, if you configure your application to have a background mode that plays music and play audio while you want your application to continue to run. You can use a silent audio file if you don't actually want to play music so long as you don't want to distribute it through the App Store, but Apple will not approve it for the App Store unless there is actual music as an actual feature in your application.
I want to know how to generate local notification at the end of the incoming call in Iphone using core telephony frame work
You can't intercept every phone call, unless your app is an app that is allowed to run in th background. Like VOIP, navigation (or other GRPS tracker) or playing audio.
You can use the apple example to see if there is a call active and set the callEventHandler block.
Then check if there the is ended by checkin if the callState is equal to CTCallStateDisconnected.
I wonder, if there's a way to get reason of applicationWillResignActive being called?
I'm developing an audio app, and I want to continue recording sound when the screen is auto locked, but I want to stop recording when incoming call occurs. How can I do that?
You can simply use the AVAudioSessionDelegate protocol methods like: beginInterruption and/or endInterruptionWithFlags: to check if the recording is interrupted and than you can do whatever you need.
In this case this approach has an advantage over registering to telephony events, because it works all the time recording, and not only for the first 10 minutes.
You can refer to the Core Telephony Framework in your application. This framework gives you the possibility of listening to the events and state of the phone on your device.
Moreover, the CTCallCenter class gives you the possibility of registering to telephony events to appropriately handle them through your application. This way you will be able to call a specific callback when an incoming call arrives, a call is started, terminated and so on. See the full list of cellular call states.
Hope this helps.
I have a video recording app. Everything works fine. Except when a phone call is received while recording.
When a phone call is received, I try to end the recording, however, any of my calls to write to an AVAssetWriter are denied. audioWriterInput appendSampleBuffer returns no, appendPixelBuffer errors out. I try to call avAssetWriter finishWriting but that returns AVAssetWriterStatusFailed.
Nothing works, my video is corrupted because it seems that my usual methods to finish up a recording session are not being allowed once a call is received.
What could I listen for to properly end a recording session when a phone call is received? The only thing I can currently do is listen for applicationWillResignActive and stop everything, but that prevents recording while a user receives a text message, etc. which would make my app work differently than the native Camera app.
Take a look at the Core Telephony framework, and specifically the CTCallCenter class. You can register an callEventHandler which is a block that accepts a CTCall object. This object describes the call state. Try to end recording when the call object indicates it's an incoming call.