Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-09-2010, 05:49 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 50
JavaWizKid is on a distinguished road
Question Bluetooth GameKit

I've found this code from a website demonstrating a bluetooth chat.

Code:
//
//  GameKitTestViewController.m
//  GameKitTest
//
//  Created by Gavi Narra on 6/16/09.
//  Copyright ObjectGraph LLC 2009. All rights reserved.
//
 
#import "GameKitTestViewController.h"
 
@implementation GameKitTestViewController
 
@synthesize mSession;
 
 
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/
 
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
 
 
 
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
 
	mPicker=[[GKPeerPickerController alloc] init];
	mPicker.delegate=self;
	mPicker.connectionTypesMask = GKPeerPickerConnectionTypeNearby | GKPeerPickerConnectionTypeOnline;
	mPeers=[[NSMutableArray alloc] init];
}
 
 
 
 
 
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
 
- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
 
	// Release any cached data, images, etc that aren't in use.
}
 
- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}
 
 
- (void)dealloc {
	[mPeers release];
    [super dealloc];
}
 
#pragma mark Events
 
-(IBAction) connectClicked:(id)sender{
//Show the connector
	[mPicker show];
}
 
#pragma mark PeerPickerControllerDelegate stuff
 
/* Notifies delegate that a connection type was chosen by the user.
 */
- (void)peerPickerController:(GKPeerPickerController *)picker didSelectConnectionType:(GKPeerPickerConnectionType)type{
	if (type == GKPeerPickerConnectionTypeOnline) {
        picker.delegate = nil;
        [picker dismiss];
        [picker autorelease];
		// Implement your own internet user interface here.
    }
}
 
/* Notifies delegate that the connection type is requesting a GKSession object.
 
 You should return a valid GKSession object for use by the picker. If this method is not implemented or returns 'nil', a default GKSession is created on the delegate's behalf.
 */
- (GKSession *)peerPickerController:(GKPeerPickerController *)picker sessionForConnectionType:(GKPeerPickerConnectionType)type{
 
	//UIApplication *app=[UIApplication sharedApplication];
	NSString *txt=mTextField.text;
 
	GKSession* session = [[GKSession alloc] initWithSessionID:@"gavi" displayName:txt sessionMode:GKSessionModePeer];
    [session autorelease];
    return session;
}
 
/* Notifies delegate that the peer was connected to a GKSession.
 */
- (void)peerPickerController:(GKPeerPickerController *)picker didConnectPeer:(NSString *)peerID toSession:(GKSession *)session{
 
	NSLog(@"Connected from %@",peerID);
 
	// Use a retaining property to take ownership of the session.
    self.mSession = session;
	// Assumes our object will also become the session's delegate.
    session.delegate = self;
    [session setDataReceiveHandler: self withContext:nil];
	// Remove the picker.
    picker.delegate = nil;
    [picker dismiss];
    [picker autorelease];
	// Start your game.
}
 
-(IBAction) sendData:(id)sender{
 
	NSString *str=@"Hello SaiBaba";
	[mSession sendData:[str dataUsingEncoding: NSASCIIStringEncoding] toPeers:mPeers withDataMode:GKSendDataReliable error:nil];
}
 
- (void) receiveData:(NSData *)data fromPeer:(NSString *)peer inSession: (GKSession *)session context:(void *)context
{
    // Read the bytes in data and perform an application-specific action.
 
	NSString* aStr;
	aStr = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
	NSLog(@"Received Data from %@",peer);
	mTextView.text=aStr;
 
 
}
 
/* Notifies delegate that the user cancelled the picker.
 */
- (void)peerPickerControllerDidCancel:(GKPeerPickerController *)picker{
 
}
 
#pragma mark GameSessionDelegate stuff
 
/* Indicates a state change for the given peer.
 */
- (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state{
 
	switch (state)
    {
        case GKPeerStateConnected:
		{
			NSString *str=[NSString stringWithFormat:@"%@\n%@%@",mTextView.text,@"Connected from pier ",peerID];
			mTextView.text= str;
			NSLog(str);
			[mPeers addObject:peerID];
			break;
		}
        case GKPeerStateDisconnected:
		{
			[mPeers removeObject:peerID];
 
			NSString *str=[NSString stringWithFormat:@"%@\n%@%@",mTextView.text,@"DisConnected from pier ",peerID];
			mTextView.text= str;
			NSLog(str);
			break;
		}
    }
}
 
@end
However when I edit it to

Code:
//
//  GameKitTestViewController.m
//  GameKitTest
//
//  Created by Gavi Narra on 6/16/09.
//  Copyright ObjectGraph LLC 2009. All rights reserved.
//
*
#import "GameKitTestViewController.h"
*
@implementation GameKitTestViewController
*
@synthesize mSession;
*
- (void)viewDidLoad
{
    [super viewDidLoad];
*
	mPicker=[[GKPeerPickerController alloc] init];
	mPicker.delegate=self;
	mPicker.connectionTypesMask = GKPeerPickerConnectionTypeNearby;
	mPeers=[[NSMutableArray alloc] init];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}
*
- (void)viewDidUnload
{
	
}
*
*
- (void)dealloc
{
	[mPeers release];
    [super dealloc];
}
*
#pragma mark Events
*
-(IBAction) connectClicked:(id)sender
{
	[mPicker show];
}
*
#pragma mark PeerPickerControllerDelegate stuff
*
- (void)peerPickerController:(GKPeerPickerController *)picker didSelectConnectionType:(GKPeerPickerConnectionType)type
{

}
*
- (GKSession *)peerPickerController:(GKPeerPickerController *)picker sessionForConnectionType:(GKPeerPickerConnectionType)type
{
	NSString *txt=mTextField.text;
*
	GKSession* session = [[GKSession alloc] initWithSessionID:@"gavi" displayName:txt sessionMode:GKSessionModePeer];
    [session autorelease];
    return session;
}
*
- (void)peerPickerController:(GKPeerPickerController *)picker didConnectPeer:(NSString *)peerID toSession:(GKSession *)session
{
	NSLog(@"Connected from %@",peerID);
    self.mSession = session;
    session.delegate = self;
    [session setDataReceiveHandler: self withContext:nil];
    picker.delegate = nil;
    [picker dismiss];
    [picker autorelease];
	// Start your game.
}
*
-(IBAction) sendData:(id)sender
{
	NSString *str=@"Hello SaiBaba";
	[mSession sendData:[str dataUsingEncoding: NSASCIIStringEncoding] toPeers:mPeers withDataMode:GKSendDataReliable error:nil];
}
*
- (void) receiveData:(NSData *)data fromPeer:(NSString *)peer inSession: (GKSession *)session context:(void *)context
{
	NSString* aStr;
	aStr = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
	NSLog(@"Received Data from %@",peer);
	mTextView.text=aStr;
}

- (void)peerPickerControllerDidCancel:(GKPeerPickerController *)picker
{
*
}
*
#pragma mark GameSessionDelegate stuff
*

- (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state
{
	switch (state)
    {
        case GKPeerStateConnected:
		{
			NSString *str=[NSString stringWithFormat:@"%@\n%@%@",mTextView.text,@"Connected from pier ",peerID];
			mTextView.text= str;
			NSLog(str);
			[mPeers addObject:peerID];
			break;
		}
        case GKPeerStateDisconnected:
		{
			[mPeers removeObject:peerID];
*
			NSString *str=[NSString stringWithFormat:@"%@\n%@%@",mTextView.text,@"DisConnected from pier ",peerID];
			mTextView.text= str;
			NSLog(str);
			break;
		}
    }
}
*
@end
It errors with EXC_BAD_ACCESS even though I've edited next to 0 code and just uncommented everything :S Very odd :S
__________________
Discover new apps through art! Sound weird? Check it out! BigAppAd!
Follow me on Twitter!
JavaWizKid is offline   Reply With Quote
Old 05-09-2010, 06:37 AM   #2 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 50
JavaWizKid is on a distinguished road
Default

It has got something to do with KPeerPickerConnectionTypeOnline. I want to remove it.
__________________
Discover new apps through art! Sound weird? Check it out! BigAppAd!
Follow me on Twitter!

Last edited by JavaWizKid; 05-09-2010 at 06:44 AM.
JavaWizKid is offline   Reply With Quote
Reply

Bookmarks

Tags
gamekit, iphone, sdk

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 408
10 members and 398 guests
7twenty7, ChrisYates, djohnson, Duncan C, gmarro, Kirkout, Retouchable, SLIC, walex, xzoonxoom
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,128
Posts: 402,921
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:04 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0