Search code examples
objective-ciosgksessiongkpeerpickercontroller

A bit of annoying warnings that still let the app work but would like to remove


I tried out an app to test bluetooth communication. It is a simple app that just sends a message in text form from one iDevice to another. Originally, this app had about 6 warnings but I fixed all but two. They are the same but deal with different delegates. One is for the GKPeerPickerControllerDelegate and the other for the GKSessionDelegate. Say the Picker error is for the GKPeerPickerController named picker, when you type (more complete example to follow):

picker.delegate = self;

the compiler says:

Passing '*const___strong' to parameter of incompatible type 'id'.

For the GKSession named session, typing

session.delegate = self;

makes the compiler say:

Sending '*const___strong' to parameter of incompatible type 'id'.

These only pop in the button to send and peerPickerController. I know that these warnings do not impede on the app's ability to function but I would like to completely update this for Xcode 4.2. This app was originally written for Xcode back when iOS 3.0 was new. Yes, I am a bit picky when it comes to writing or practicing code, it must not contain any errors/warnings whenever possible.

These are the code blocks where the warning occur:

-(IBAction)btnConnect:(id)sender{
    picker = [[GKPeerPickerController alloc] init];
    picker.delegate = self;  //Warning here
    picker.connectionTypesMask = GKPeerPickerConnectionTypeNearby;

    [connect setHidden:YES];
    [disconnect setHidden:NO];
    [picker show];
}

-(void)peerPickerController:(GKPeerPickerController *)PCpicker didConnectPeer:(NSString *)peerID toSession:(GKSession *)session{
    self.currentSession = session;
    session.delegate = self;  //Warning here
    [session setDataReceiveHandler:self withContext:nil];
    PCpicker.delegate = nil;

    [PCpicker dismiss];
}

Edit:

The header has this:

    @interface BTViewController : UIViewController{
GKSession *currentSession;
IBOutlet UITextField *txtMessage;
IBOutlet UIButton *connect;
IBOutlet UIButton *disconnect;

GKPeerPickerController *picker;

}


Solution

  • I believe whatever class self is may not be adopting the GKPeerPickerControllerDelegate and GKSessionDelegate formal protocols. Can you post your interface header?

    EDIT

    Casting to id will clear the warnings, but you really didn't "fix" anything...looking at the class header, it is not adopting the protocols that the delegates are expecting.

    Modify your interface to adopt those protocols:

    @interface BTViewController : UIViewController <GKPeerPickerControllerDelegate, GKSessionDelegate> {