IT tutorials
 
Mobile
 

iPhone Developer : Creating an “Online” GameKit Connection

4/16/2013 9:40:39 PM
- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire

In the GameKit world, “online” currently means any valid connection style other than Bluetooth. You might use a local WLAN network to connect to another device on the same network or connect through WWAN (i.e., the cellular service) or WiFi to a remote Internet-based host. GameKit takes you only so far as the dialog shown in Figure 1. By selecting Online, your user depends on you to create a custom connection to another device or service.

Figure 1. The Online GameKit connection means “bring your own networking.” (Please note that the Send button shown on the keyboard here is a standard Return key. In this recipe, data is sent as it is typed.)


You create this two-item dialog by supplying the online option to the peer picker mask. In all other ways, there’s no change in how you create and present a standard GameKit peer picker controller.

- (void) startConnection
{
    if (!self.isConnected)
    {
        GKPeerPickerController *picker = [[GKPeerPickerController
            alloc] init];
        picker.delegate = self;
        picker.connectionTypesMask = GKPeerPickerConnectionTypeNearby |
            GKPeerPickerConnectionTypeOnline;
        [picker show];
        if (self.viewController)
            self.viewController.navigationItem.rightBarButtonItem =
                nil;
    }
}

Catch the user selection in the peerPickerController:didSelectConnectionType: callback. You can assume that if the user selected Nearby that all the handshaking dialogs are taken care of for you. Should the user select Online, however, it’s up to you to move things to the next step. You need to dismiss the picker and display the next stage of the connection task. Here, control passes away from the peer picker. 

- (void)peerPickerController:(GKPeerPickerController *)picker
    didSelectConnectionType:(GKPeerPickerConnectionType)type
{
    if(type == GKPeerPickerConnectionTypeOnline)
    {
        [picker dismiss];
        [picker release];
        [BonjourHelper sharedInstance].sessionID = self.sessionID;
        [BonjourHelper sharedInstance].viewController =
            self.viewController;
        [BonjourHelper sharedInstance].dataDelegate =
            self.dataDelegate;
        [BonjourHelper connect];
    }
}

As Recipe 1 demonstrates, almost no changes are needed from the BonjourHelper side of things. The Connect button on the navigation bar must point back to GameKit’s connect method, not to BonjourHelper’s. This ensures that users can finish a Bonjour connection and then move on to a Bluetooth one without restarting the application.

Recipe 1. Updating the Macro Code to Use GameKit’s Version of Connect
#define GBARBUTTON(TITLE, SELECTOR) [[[UIBarButtonItem alloc] \
initWithTitle:TITLE style:UIBarButtonItemStylePlain \
target:[GameKitHelper class] action:SELECTOR] autorelease]

if (sharedInstance.viewController)
    sharedInstance.viewController.navigationItem.rightBarButtonItem =
        GBARBUTTON(@"Connect", @selector(connect));


Additionally, you might think the Info.plist file needs a UIRequiresPersistentWiFi key set to the Boolean value of true. Avoid doing this. Instead, check for WiFi only when you are ready to attempt to create a WiFi connection, i.e., when the user clicks Online. GameKit Bluetooth connections don’t need persistent WiFi although standard Bonjour ones do. Don’t require your users to connect to a (possibly nonexistent) WiFi service when Bluetooth is sufficient for Nearby gaming.

 
Others
 
- Java ME on Symbian OS : Handling Transitions Between Foreground and Background
- Java ME on Symbian OS : Handling JSR Fragmentation
- IPad : Using Popular and Critical Apps - Using Bento
- IPad : Using Popular and Critical Apps - Using iTap VNC
- BlackBerry Development : Pushing Data to Internal Users - Browser Push
- BlackBerry Application Data Push : How the Application Data Push Process Works
- Windows Phone 8 : Controls - Data Binding (part 4) - Control Templates
- Windows Phone 8 : Controls - Data Binding (part 3) - Data Binding Errors
- Windows Phone 8 : Controls - Data Binding (part 2) - Improving Scrolling Performance, Binding Formatting, Converters
- Windows Phone 8 : Controls - Data Binding (part 1) - Simple Data Binding, Using a DataTemplate
 
25 Inspiring Game of Thrones Quotes
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
programming4us programming4us
 
Popular tags
 
Video Tutorail Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS