Giter Site home page Giter Site logo

macpu / mpbluetoothkit Goto Github PK

View Code? Open in Web Editor NEW
165.0 7.0 30.0 223 KB

This is a block-based framework for building Bluetooth iOS apps using the CoreBluetooth Framework.Its a very powerful and useful,and very easy to use it

License: MIT License

Objective-C 95.45% Ruby 4.55%

mpbluetoothkit's Introduction

#MPBluetoothKit This is a block-based framework for building Bluetooth iOS apps using the CoreBluetooth Framework.Its a very powerful and useful,and very easy to use it . originally developed for BI-CI

####Version v0.1

Why you should use this framework

  • ObjectiveC Block-based API for Bluetooth LE communication.
  • It provide a easiest way to use CoreBluetooth framework.
  • This project is activity.
  • It provide some very useful tools

##How to use it

manual

download repository and add MPBluetoothKit/MPBluetoothKit to your project

import "MPBluetoothKit.h"

cocoapods

pod 'MPBluetoothKit','~> 0.1.0'

then

import "MPBluetoothKit.h"

###Scan for peripheral

MPCentralManager *centralManager = [[MPCentralManager alloc] initWithQueue:queue options:options];
[centralManager scanForPeripheralsWithServices:nil options:nil withBlock:^(MPCentralManager *centralManager,MPPeripheral *peripheral,NSDictionary *advertisementData,NSNumber *RSSI){

  }];

###Connecting to a Peripheral

[centralManager connectPeripheral:peripheral options:nil withSuccessBlock:^(MPCentralManager *centralManager, MPPeripheral *peripheral) {

  }withDisConnectBlock:^(MPCentralManager *centralManager, MPPeripheral *peripheral, NSError *error) {

    }];

###Read a Characteristic there is two way to read a Characteristic

[peripheral readValueForCharacteristic:(nullable MPCharacteristic *)characteristic withBlock:^(MPPeripheral *peripheral,MPCharacteristic *characteristic,NSError *error){

  }];
[characteristic readValueWithBlock:^(MPPeripheral *peripheral,MPCharacteristic *characteristic,NSError *error){

  }];

###Write to a Characteristic there is two way to write to a characteristic


[peripheral writeValue:(nullable NSData *)data
 forCharacteristic:(nullable MPCharacteristic *)characteristic
              type:(CBCharacteristicWriteType)type
         withBlock:^(MPPeripheral *peripheral,MPCharacteristic *characteristic,NSError *error){
         }];
[characteristic writeValue:(nullable NSData *)data
              type:(CBCharacteristicWriteType)type
         withBlock:^(MPPeripheral *peripheral,MPCharacteristic *characteristic,NSError *error){
         }];

more detail on MPBluetoothKit

##Required

  • CoreBluetooth.framework
  • iOS 7.0 or later

##TODO v0.2

  • add WatchDog reconnect when disconnected peripheral

mpbluetoothkit's People

Contributors

macpu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

mpbluetoothkit's Issues

通知订阅

H2 希望楼主写一些通知订阅的demo,很需要。

RSSI问题

建议didDiscoverPeripheral时,就把RSSI写入对应的MPPeripheral中,再去readRSSI麻烦。

扫描自动停止&Mac地址获取

使用的时候发现,开始扫描后,一直没有停止,还需要自己写一个延时停止的方法,建议增加一个扫描方法,可以设定扫描时间。这样更方便使用。仅仅是建议。
还有就是你的博客上的获取Mac地址的方法,在180A的2A23下确实能得到这个值,前提是蓝牙端提供了这个service 的charactrstic的情况下。但是我用swift调用的时候
NSString *value = [NSString stringWithFormat:@"%@",characteristic.value];
这个value不能转换为string,需要转换成二进制
var hexadecimalString: String {
var bytes = [UInt8](repeating: 0, count: count)
copyBytes(to: &bytes, count: count)

    let hexString = NSMutableString()
    for byte in bytes {
        hexString.appendFormat("%02x", UInt(byte))
    }
    return NSString(string: hexString) as String
}

有需要的人看看,这也是其它地方看到的。
在OC中没有试。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.