2010. 5. 17. 16:53
connect several iPhones using Gamekit via Bluetooth w/o GKPeerPickerController 개발 - iPhone/참조 사이트/글2010. 5. 17. 16:53
http://www.iphonedevsdk.com/forum/iphone-sdk-development/40710-gamekit-api.html
Registered Member
Join Date: Feb 2010
Posts: 3
|
Quote:
Anyways, here's a step by step guide: 1. Init the session, just like you did. 2. Set the delegate and the isAvailable property. 3. Set the data receiver. Code: self.curSession = [[GKSession alloc] initWithSessionID:nil displayName:nil sessionMode:GKSessionModePeer]; self.curSession.delegate = self; self.curSession.available = YES; self.curSession.disconnectTimeout = 0; // Set data handler. [self.curSession setDataReceiveHandler:self withContext:nil]; 5. Wait. 6. The delegates method "didChangeState" should be called. The state should be "GKPeerStateAvailable". Once there, connect to that peer, using the GKSession's "connect" method. Code: - (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state { // Retain new session. self.curSession = session; // Do stuff depending on state. switch (state) { case GKPeerStateAvailable: [session connectToPeer:peerID withTimeout:0]; break; } } 8. The delegates method "didReceiveConnectionRequestFromPeer" should be called. Accept the connection there using the sessions "acceptConnectionFromPeer" method. Code: - (void)session:(GKSession*) session didReceiveConnectionRequestFromPeer:(NSString*) peerID { [session acceptConnectionFromPeer:peerID error:nil]; } 10. Boom, you are done. Don't forget to handle the other delgates methods, e.g. disconnecting the peer in "connectionToPeerFailed". Also, disconnect all peers and release the Bluetooth session before quitting the app. And, if for the love of god you just can't get it to work, try restarting the device. Sometimes BT just stopped working for me. Last edited by Regnits; 02-17-2010 at 03:08 AM. |
'개발 - iPhone > 참조 사이트/글' 카테고리의 다른 글
Don’t use UITableViewController. Really. (0) | 2010.10.14 |
---|---|
cocos2d - PinchZoomLayer Example App - like fieldrunners (0) | 2010.09.28 |
cocos2d - Path Finding and Tile Maps- Sample App (0) | 2010.09.28 |
Jeff LaMarche 블로그: OpenGL ES 관련 참고 사이트 (0) | 2010.06.11 |
소개:아이폰 앱 광고에서 앱 이름과 아이콘의 중요성에 대한 글 (0) | 2010.05.17 |