XCtest : how can I simulate a phone call interruption in UItest for ios - xctest

I'm looking for a way can simulate an interruption like phone calls when doing xctesting.

Related

Resuming iPod Playback after calling AVAudioSession setActive:NO

What's the best way to resume playback of the ipod or other audio sessions after your app has completed using its session?
NOTE I've already tried calling...
[_session setActive:NO
withFlags:AVAudioSessionSetActiveFlags_NotifyOthersOnDeactivation
error:outError];
I'm building an iOS VoIP app which uses AVAudioSessionCategoryPlayAndRecord as its category and kAudioSessionMode_VoiceChat as its mode. To simplify handling of audio session management, I've got a singleton which listens for notifications on application state and other important events. However, the above code does not seem to cause the music to resume on the iPod app.
Finally, we've also noticed that the music controls that are shown on the bottom of the screen when the home button is double tapped act as if our application is the one playing audio. Yet we've already set it to be inactive.
Would love to understand more about what's going on here if anyone has any clue.
I seems to me that you are unable to notify the iOS that you no longer require an audio session. Are you sure that the call to "setActive" doesn't fail? Or maybe somewhere else in the code you reactivate your session.
Other than that, the Music application should be able to re-gain it's audio as soon as the system realizes you are not using it. This can be accomplished by third-party applications using the AVAudioSessionInterruptionNotification notification. For debugging you might try adding yourself as observer and see if your callback gets called. So, if you successfully deactivate your session, other applications should be able to do the rest.

Xcode iOS: Calling a number from the app

I across the following code:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel://8005551212"]];
on : Making phone calls on iPhone
But, it does not work for me in the simulator.
I have connected the IBAction(callphone) to the ViewController(TouchUpInside). I am now not sure, is it because I am checking my code in simulator? I do not get a dialog box. Please advice.
I tried putting log statements and the action does get called since the log stamtments that I wrote to test is being printed
Can you make a phone call from your Mac? No. That's why the simulator doesn't work when you try to open a tel:// URL. You must do this from a device that can make a call: an iPhone, but not an iPad or iPod touch.

Sound does only work on Device but not in Simulator

I am playing some short sounds on my iPad like so: Play a short sound in iOS
I am using a caf file which I can successfully play from the Finder. Now I went through quite a bit of a hassle trying to achieve the playback of the sound and I am curious what might be the problems which I don't seem to understand:
Option 1: When I create the SystemSoundID and then play it right away I don't hear anything on the device and the simulator.
Option 2: When I create an instance variable for the SystemSoundID and initialize it in viewDidLoad I manage to play sound but only on the iPad, not the Simulator.
Option 3: Instead of using SystemSoundID I can also use AVAudioPlayer to playback a .wav file which then works on both the iPad and the Simulator but here I need to create the AVAudioPlayer in viewDidLoad otherwise I won't get any sound if I do everything in one go.
The best option currently seems to be Option 3 because it works on both the Simulator and the iPad, but because I need to pre-initialize the Player I would need an AVAudioPlayer instance for every different sound that I want to play, which does not seem to be very memory-wise...
Is there something that I am missing and is it possible to play sounds on both platforms using the AudioToolbox framework (Option 1 & Option 2)
I wrote a library to simplify all this. It wraps AVAudioPlayer, and works fine on both the device and simulator.
https://github.com/nicklockwood/SoundManager
The code is fairly straightforward, although I do some semi-clever stuff to initialise the audio player. If you don't want to use the library you can just copy the code.
A word of warning though - the simulator throws some odd exceptions internally whenever you use AVAudioPlayer. They don't affect the app at all, but if you have enabled break-on-exceptions in Xcode then the app will drop into the debugger a few times during startup and you'll have to manually resume, which may freak you out if you're not expecting it.

iOS - Open browser before going to background

I'm writing following code that opens browser when app will be going to background:
- (void)applicationWillResignActive:(UIApplication *)application
{
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.google.com"]];
}
but its not opening. Any suggestions?
Can I open browser in "applicationWillResignActive" or not?
You code looks fine so I guess that iOS won't let you do it. Your app has been told to go into the background - you don't get to open new apps!
PS :
Why would you ever want to do this - surely this will just really really annoy the user?

Callback for kAudioSessionProperty_AudioRouteChange not called in one case

I want to be notified if headphones are plugged in or plugged out. I'm currently doing this using a property listener like this:
AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, myCallback, self);
This works perfectly well in all cases except in one, it goes like this:
Launch, iPhone is unmuted, no headphones plugged in
Switch the mute button on: The callback is called, good
Plug in the headphones now: Callback is not called, not good
Is there another property I should consider? Is there a special case involving the mute button I'm not aware of?
I'm using an iPhone 3GS and iOS 4.1.
Thanks a lot for any help!
Patrick
This bug/feature only happens when using an audio session category affected by the silent switch (e.g. kAudioSessionCategory_SoloAmbientSound). kAudioSessionCategory_MediaPlayback for example works as expected.