title: iOS 4 bluetooth discovery doesn't work
body: <p>I'm reading "beginning iPad application development", and at the bluetooth chapter i'm testing the code exactly as it appears at the book. The only difference is that the book was for 3.2 and I'm using XCODE 4 for iOS >4.0.</p>
  
  <p>XCODE does not throw any error or warning, it builds correctly, but when testing at the iPhone it doesn't discover other devices.</p>
  
  <p>What's wrong?</p>
  
  <p>The viewController.h looks like:</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import &lt;GameKit/GameKit.h&gt;
  
  @interface pruebaBluetoothViewController : UIViewController
  &lt;GKSessionDelegate, GKPeerPickerControllerDelegate&gt; {
  GKSession *currentSession;
  IBOutlet UITextField *txtMessage;
  IBOutlet UIButton *connect;
  IBOutlet UIButton *disconnect;
  GKPeerPickerController *picker;
  }
  @property (nonatomic, retain) GKSession *currentSession;
  @property (nonatomic, retain) UITextField *txtMessage;
  @property (nonatomic, retain) UIButton *connect;
  @property (nonatomic, retain) UIButton *disconnect;
  -(IBAction) btnSend:(id) sender;
  -(IBAction) btnConnect:(id) sender;
  -(IBAction) btnDisconnect:(id) sender;
  @end
  </code></pre>
  
  <p>While the .m looks like:</p>
  
  <pre><code>#import "pruebaBluetoothViewController.h"
  
  @implementation pruebaBluetoothViewController
  
  @synthesize currentSession;
  @synthesize txtMessage;
  @synthesize connect;
  @synthesize disconnect;
  
  - (void)viewDidLoad {
  [connect setHidden:NO];
  [disconnect setHidden:YES];
  [super viewDidLoad];
  }
  -(IBAction) btnConnect:(id) sender {
  picker = [[GKPeerPickerController alloc] init];
  picker.delegate = self;
  picker.connectionTypesMask = GKPeerPickerConnectionTypeNearby;
  [connect setHidden:YES];
  [disconnect setHidden:NO];
  [picker show];
  }
  - (void)peerPickerController:(GKPeerPickerController *)pk
  didConnectPeer:(NSString *)peerID
  toSession:(GKSession *) session {
  self.currentSession = session;
  session.delegate = self;
  [session setDataReceiveHandler:self withContext:nil];
  picker.delegate = nil;
  [picker dismiss];
  [picker autorelease];
  }
  - (void)peerPickerControllerDidCancel:(GKPeerPickerController *)pk {
  picker.delegate = nil;
  [picker autorelease];
  [connect setHidden:NO];
  [disconnect setHidden:YES];
  }
  -(IBAction) btnDisconnect:(id) sender {
  [self.currentSession disconnectFromAllPeers];
  [self.currentSession release];
  currentSession = nil;
  [connect setHidden:NO];
  [disconnect setHidden:YES];
  }
  - (void)session:(GKSession *)session
  peer:(NSString *)peerID
  didChangeState:(GKPeerConnectionState)state {
  switch (state) {
  case GKPeerStateConnected:
  NSLog(@"connected");
  break;
  case GKPeerStateDisconnected:
  NSLog(@"disconnected");
  [self.currentSession release];
  currentSession = nil;
  [connect setHidden:NO];
  [disconnect setHidden:YES];
  break;
  }
  }
  - (void)dealloc {
  [txtMessage release];
  [currentSession release];
  [super dealloc];
  }
  
  - (void) mySendDataToPeers:(NSData *) data {
  if (currentSession)
  [self.currentSession sendDataToAllPeers:data
  withDataMode:GKSendDataReliable
  error:nil];
  }
  -(IBAction) btnSend:(id) sender {
  //---convert an NSString object to NSData---
  NSData* data;
  NSString *str = [NSString stringWithString:txtMessage.text];
  data = [str dataUsingEncoding: NSASCIIStringEncoding];
  [self mySendDataToPeers:data];
  }
  - (void) receiveData:(NSData *)data
  fromPeer:(NSString *)peer
  inSession:(GKSession *)session
  context:(void *)context {
  //---convert the NSData to NSString---
  NSString* str;
  str = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Data received"
  message:str
  delegate:self
  cancelButtonTitle:@"OK"
  otherButtonTitles:nil];
  [alert show];
  [alert release];
  }
  </code></pre>