iOS8 Bluetooth Device reconnection (retrieve) Swift implementation

Source: Internet
Author: User

Today the app writes about the Bluetooth re-connect phase, previously written for SDK 6.0, the Bluetooth device's reply is through

-(void) Retrieveperipherals:(nsarray *)peripheraluuids

And then callback

Centralmanager:didretrieveperipherals:

function to get an array that can reply to the device.

After SDK7,-(void) Retrieveperipherals:(nsarray *)peripheraluuids was abolished and replaced by

This function will returns a list of known peripherals by their identifiers.

At first I thought that the function was called, and the connection operation was done in the callback function, and it was later discovered that the callback function in SDK6.0 was to return a list of known peripherals by their identifiers. Instead of using the callback function now, Retrieveperipheralswithidentifiers: The return value is a list of known peripherals by their identifiers. This makes the code more concise, which allows direct connection to these peripherals.

The simple code is as follows:

var Identiferarray = array<nsuuid>() identiferarray.append (peri.identifer)//  Add Identider to get Identiferarrayvar knownperipherals = mycentralmanager! . Retrieveperipheralswithidentifiers (Identiferarray)  for inch knownperipherals {    mycentralmanager!. Connectperipheral (P, options:nil)}

iOS8 Bluetooth Device reconnection (retrieve) Swift implementation

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.