1、创建连接控制器(IBAction)connectclick:(id)sender/I,创建GKPeerPickerController连接控制器GKPeerPickerController picker GKPeerPickerController new;AGKPeerPickerControlleris deprecated:first deprecated in iOS 7.0-Use MCBrowserViewContr./2.设置代理-获取数据picker.delegate self;/3,显示控制器-show此控制器和AlertView很像,不是全屏的,不用pushmodalpic
2、ker show当连接到另一台手机后会被调用0 pragma mark GKPeerPickerController代理方法pm0atat-Obiective-G目此方法在连接到另一台设备时,会调用Location Relative to Group日peerID:另一台设备的IDe5s1on:会话类,用于接收和发送数据米/-(void)peerPickerController:(GKPeerPickerController*)pickerdidConnectPeer:(NSString*)peerID toSession:(GKSession*)sessionter.mLooking for
3、 Other iPad,iPhone,or iPod Touch/1,保留sess1onself.session session;Devices./2,设置句柄(设置代理)-一将来一旦受到数据,将由句柄的方法来处理数据self.session setDataReceiveHandler:self withContext:nil;Cancel/3。消失控制器picker dismiss】:Taxt Encoding Defauit-Lnicode(UT.允从另一合手机接收到数据会调用0pragma mark接收到数据的时候,会调用此方法来处理(void)receiveData:(NSData*)
4、data fromPeer:(NSString*)peerinSession:(GKSession*)session context:(void*)context23/1,将Data转换成image对象4UIImage*image UIImage imagewithData:data;5/12,然后设置到界面上7self.imageview.image image;a发送图片pragma mark发送照片方法-(IBAction)sendPhotoclick:(id)sender/1,将image转换成DataNSData*data UIImageJPEGRepresentation(self.imageview.image,0.5):/2,使用会话类发送数据/*GKSendDataReliable,如果发送失败,会重新发送,直到成功GKSendDataUnreliable,发送一次就不管了米/self.session sendDataToAllPeers:data withDataMode:KSendDataReliable error:ni