iOS Development Bluetooth (i) Gamekit

Source: Internet
Author: User

implementation of Bluetooth in IOS 4 frames are available in IOS for Bluetooth connectivity
  1. Gamekit.framework(simple to use) can only be used for connections between IOS devices , more for games (such as Gobang), expiring from IOS7
  2. multipeerconnectivity.framework can only be used for connections between IOS devices, introduced from IOS7 , primarily for file sharing (sandbox-only files)

  3. externalaccessory.framework can be used for third-party Bluetooth device interaction , but Bluetooth devices must be certified by Apple MFi (less domestically)

  4. Corebluetooth.framework(nowadays popular) can be used for third-party Bluetooth device interaction and must support Bluetooth 4.0 hardware is at least 4sand the system is at least iOS6 Bluetooth 4.0 is known for its low power consumption and is generally called BLE At present, the use of more cases: sports hand bad, embedded devices, smart home

Let's start by learning Gamekit this way, first introducing Gamekit

1 #import <GameKit/GameKit.h>

Let's draw a button on the interface first.

Add the following code to the button's Click event

1     // Create a Connection object 2     Gkpeerpickercontroller *PPC = [[Gkpeerpickercontroller alloc] init]; 3     // Set up proxy 4     Ppc. delegate = self ; 5     // Show 6     [PPC show];

Let the controller comply with the protocol

1 @interface Viewcontroller () <GKPeerPickerControllerDelegate>23@end

Implementation protocol

1 -(void) Peerpickercontroller: (Gkpeerpickercontroller *) Picker Didconnectpeer: (NSString *) Peerid Tosession: (Gksession *) session2{3     4 }

You can see that after the connection is successful, the Protocol method will give us the Peerid and Session object session, with the session object, we can use it to send data

iOS Development Bluetooth (i) Gamekit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.