Cov txheej txheem:

Yooj Yim IOS App rau BLE Cov Qauv: 4 Kauj Ruam
Yooj Yim IOS App rau BLE Cov Qauv: 4 Kauj Ruam

Video: Yooj Yim IOS App rau BLE Cov Qauv: 4 Kauj Ruam

Video: Yooj Yim IOS App rau BLE Cov Qauv: 4 Kauj Ruam
Video: Sib Hawm Dhau (Time Passed) Music Video by: Deeda/Dib Xwb 2024, Kaum ib hlis
Anonim
Yooj Yim IOS App rau BLE Cov Qauv
Yooj Yim IOS App rau BLE Cov Qauv

Cov lus qhia no taug kev hla qhov koj tuaj yeem tsim iOS app nrog kev ua haujlwm yooj yim heev. Cov Lus Qhia no yuav tsis mus dhau tag nrho cov txheej txheem ntawm kev ua iOS BLE app. Nws yuav tsuas yog muab cov ntsiab lus qib siab ntawm qee cov ntsiab lus tseem ceeb hauv app. Los ntawm qhov cia siab tias koj tuaj yeem rub tawm qhov haujlwm thiab ua si nrog tus lej koj tus kheej kom kawm paub ntau ntxiv txog kev ua tiav.

Kuv tab tom tham nrog RN4871 BLE tus qauv hauv kuv qhov haujlwm. Tshwj xeeb RN4871 Nyem Pawg Thawj Coj uas yog tsim los ntawm MikroElektronika. Cov Nyem Nyem no tuaj yeem pom ntawm Mikro lub vev xaib zoo li lwm lub vev xaib faib khoom xws li DigiKey, Mouser, thiab lwm yam. tawm ntawm lub thawv lawv tau npaj xa thiab txais cov ntaub ntawv yam tsis xav tau kev teeb tsa. Kuv tau muaj ntau txoj hauv kev ntau zaus uas kuv tau yuav tus nqi pheej yig $ 5 online thiab yuav tsum nyeem tag nrho cov ntawv teev tseg txhawm rau txheeb xyuas seb yuav teeb tsa nws li cas. Rau kuv uas yog kwv yees li 2-4 teev ua haujlwm sim teeb tsa tus qauv ua ntej kuv tuaj yeem xa cov ntaub ntawv! Cov nyem cov laug cam no zoo li ua haujlwm tawm ntawm lub thawv tsis muaj mob taub hau yog li lawv tau txais ntiv tes xoo los ntawm kuv!

Txawm hais tias daim ntawv thov iOS no tau tsim los sib tham nrog RN4871 thiab RN4870, tib txoj cai no tuaj yeem siv rau lwm yam BLE cov qauv ib yam nkaus (nrog qee qhov kev hloov kho qhov tseeb ntawm chav kawm).

Xav tias dawb siv cov cai tab sis koj nyiam! Kuv tsis yog tus kws tshaj lij tsim app yog li zam txim rau kuv yog tias muaj dab tsi hauv nws ua rau koj nkag siab:)

Kauj Ruam 1: Ntxiv BLE Tso Cai

Ntxiv BLE Tso Cai
Ntxiv BLE Tso Cai

Ib qho tseem ceeb tshaj yog kev tso cai ntxiv los siv BLE hauv app.

Qhov chaws ntawm lub app no muaj tus lej ntxiv hauv cov ntaub ntawv info.plist. Tsis pub twg paub - Bluetooth Cov Khoom Siv Siv Ib Leeg piav qhia qhov tseem ceeb xav tau ntxiv txhawm rau siv BLE. Tsis tas yuav ntxiv tus yuam sij Bluetooth no, Xcode yuav muab qhov yuam kev rau koj thaum koj sim khiav lub app.

Kauj Ruam 2: Cov Ntaub Ntawv Bluetooth.swift

Qhov no yog arguably cov ntaub ntawv tseem ceeb tshaj plaws hauv txoj haujlwm no. Hauv cov ntaub ntawv Bluetooth.swift no, lub ntiaj teb hom khoom ntawm hom BluetoothClass tau tsim. Lub hom phiaj thoob ntiaj teb no tau pib los ntawm BluetoothHomeViewController thaum nws tshwm.

Cov khoom tuav ob qho tib si centralManager sib txawv thiab ib qho sib txawv ntawm qhov sib txawv. Thaum cov kev hloov pauv no tau piav qhia, lawv tau siv thoob plaws hauv lub app. Los ntawm kev siv peb tus kheej chav kawm, peb zam kev xav tau pib ntau zaus ntawm centralManager thiab cov khoom siv sab nraud, yog li peb tuaj yeem siv tib yam khoom txawm hais tias muaj pes tsawg viewControllers lossis cov ntaub ntawv raug ntxiv. Ib qho ntxiv peb tsis tas yuav txhawj xeeb txog kev hla ib qho khoom mus rau ntau cov ntaub ntawv thiab saib Cov Tswj. Qhov ntawd tuaj yeem ntxhov siab!

Cov ntaub ntawv no muaj txhua yam uas tau siv los tshawb pom, txuas thiab tham nrog ib tus neeg sab nraud.

Nws kuj tseem muaj cov kev pabcuam UUID uas peb yuav tshuaj xyuas nrog rau rxUUID (tau txais), thiab txUUID (xa). Yog tias koj xav siv tus qauv sib txawv nrog cov app no, txhua yam uas koj yuav tsum tau ua yog hloov cov txiaj ntsig no kom phim UUIDs ntawm tus qauv tshiab uas koj tab tom siv.

Kauj ruam 3: ViewControllers

Cov app no yooj yim heev. Tsuas muaj ob tus ViewControllers: ib qho xa cov ntaub ntawv rov qab los, thiab ib qho los tshuaj xyuas cov khoom siv ib sab.

BluetoothHomeViewController yam tseem ceeb kom nco ntsoov:

  • Peb tsim cov ntawv ceeb toom rau thaum peb cov khoom siv Bluetooth pom ib qho khoom siv sab nraud thiab thaum twg peb cov khoom siv Bluetooth tau txais cov lus.
  • Peb sau npe yuav cov ntawv ceeb toom tau txais.

    Qhov no pib tsim kev cuam tshuam, thaum nyob hauv qhov kev saib xyuas no, txhua lub sijhawm peb tau txais qee yam. Tom qab ntawd peb tso saib yam peb tau txais hauv kab lus

ScannerViewController yam tseem ceeb kom nco ntsoov:

  • Peb sau npe yuav pom cov ntawv ceeb toom ib puag ncig.

    Qhov no tsim kev cuam tshuam, thaum nyob rau hauv qhov kev saib xyuas no, txhua lub sijhawm pom cov khoom siv tshiab uas zoo ib yam nrog peb cov kev pabcuam UUID kom peb tuaj yeem rov qab tau lub rooj tso saib cov khoom siv muaj

Kauj Ruam 4: Qhov ntawd Zoo Li Nws

Tau kawg muaj lwm yam ntxiv hauv app. Txawm li cas los xij kuv tsuas yog piav qhia txog yam uas yuav tsis meej pem hauv qhov kev siv. Cia siab tias seem ntawm cov cai uas kuv tsis tau tham txog yog tus kheej piav qhia.

Ib zaug ntxiv cov cai no yuav tsum tuaj yeem siv nrog lwm cov qauv BLE sab nraum RN4871. Koj yuav tsum tsuas yog xav hloov kho UUIDs sab hauv ntawm Bluetooth.swift cov ntaub ntawv.

Thov rub tawm txoj haujlwm thiab ua si nrog tus lej koj tus kheej kom kawm tau zoo npaum li cas txhua yam tau ua tiav. Txoj cai yooj yim heev yog li koj tuaj yeem ntxiv thiab hloov kho kom haum rau koj tus kheej daim ntawv thov.

Zoo siab Coding!

-ChocolateDrizzle

Pom zoo: