Open main menu

lensowiki β

Changes

IPhone development tips

1,431 bytes added, 08:10, 28 March 2010
tethering note
*Xcode is unable to connect to your device for some reason
:Sometimes Xcode will show your phone as being connected but will be unable to initialize it for development purpose for some bizarre reason. Simply restart your phone to fix the problem.
*GPS shuts off when user locks the screen manually or the device auto-locks
:You can use <tt>[UIApplication sharedApplication].idleTimerDisabled = YES;</tt> to keep the screen on, but this is bad for the screen itself and takes a nice toll on battery life. Instead, set up an <tt>AVAudioSession</tt> with the <tt>AVAudioSessionCategoryPlayback</tt> category, then set the <tt>kAudioSessionProperty_OverrideCategoryMixWithOthers</tt> property (so that the user's iPod can keep playing) and a more aggressive I/O buffer using <tt>kAudioSessionProperty_PreferredHardwareIOBufferDuration</tt>. Then, use <tt>AVAudioPlayer</tt> to play a "recording" of total silence on endless loop for when you need to keep GPS running. <em>Note</em>: accelerometer and WiFi still shut off when the screen is locked.
:Note also that to test this properly, you *must* untether your device, as when your device is connected to power, it never enters low-power mode (WiFi and GPS stay on, even if you don't play any sound).
*Calling <tt>[[AVAudioSession sharedInstance] setPreferredIOBufferDuration:</tt> always errors, regardless of what value you use!
:See [http://stackoverflow.com/questions/1714507/recording-audio-on-iphone-error-with-setpreferrediobufferduration/2530737#2530737 my response on StackOverflow]. Basically this is a bug in the interface and you '''have''' to use the plain C method instead of the Objective-C one to get this to work.
1,273
edits