implementation of Bluetooth in IOS 4 frames are available in IOS for Bluetooth connectivity
- Gamekit.framework(simple to use) can only be used for connections between IOS devices , more for games (such as Gobang), expiring from IOS7
multipeerconnectivity.framework can only be used for connections between IOS devices, introduced from IOS7 , primarily for file sharing (sandbox-only files)
externalaccessory.framework can be used for third-party Bluetooth device interaction , but Bluetooth devices must be certified by Apple MFi (less domestically)
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