Forum Xamarin.iOS

What is best way to add bluetooth low energy (BLE) to XAMARIN.IOS: CoreBluetooth or BLE plugin?

dbelldbell Member ✭✭

I've seen 3 plugins:
WOJCIECH
ARITCHIE
XABRE

But the first 2 don't build. And the 3rd crashes on my iPhone.

So I want to know if it's less work to just implement CoreBluetooth on my Xam.IOS app or to debug those plugin problems.

Answers

  • ColeXColeX Member, Xamarin Team Xamurai
    edited September 2020

    But the first 2 don't build. And the 3rd crashes on my iPhone.

    What is the exact problem? Is there any error message ?

    Did you follow the instruction ?

  • dbelldbell Member ✭✭

    I posted all the error details here...

    https://forums.xamarin.com/discussion/184893/how-can-i-communicate-with-bluetooth-low-energy-ble-on-xamarin-ios/p1?new=1

    "Did you follow the instruction ?" THANK YOU! I will follow...

  • dbelldbell Member ✭✭

    Those instructions are for the ARITCHIE plugin. But does it support xamarin.IOS ? I don't see xamarin.ios anywhere in the instructions.

  • ColeXColeX Member, Xamarin Team Xamurai
    edited September 2020

    You can not use https://github.com/xabre/xamarin-bluetooth-le directly in Xamarin.iOS , it is used for xamarin.Forms .

    Refer to the following steps .

    1. Add permissions in info.plist .

        <key>UIBackgroundModes</key>
            <array>
             <!--for connecting to devices (client)-->
            <string>bluetooth-central</string>
      
        <!--for server configurations if needed-->
        <string>bluetooth-peripheral</string>
      

      <!--Description of the Bluetooth request message (required on iOS 10, deprecated)-->
      <key>NSBluetoothPeripheralUsageDescription</key>
      <string>YOUR CUSTOM MESSAGE</string>
      
        <!--Description of the Bluetooth request message (required on iOS 13)-->
       <key>NSBluetoothAlwaysUsageDescription</key>
       <string>YOUR CUSTOM MESSAGE</string>
      
    2. Check the implmentations according to the usage , you could find them in iOS part .

    3. Intergrate the implmentation into your iOS project and call corresponding methods.

  • dbelldbell Member ✭✭

    "You can not use https://github.com/xabre/xamarin-bluetooth-le directly in Xamarin.iOS , it is used for xamarin.Forms ."

    My question is about XAMARIN.IOS, not XAMARIN.FORMS.

    Downloaded XABRE project, installed Plugin.BluetoothLE, opened BLE.sln and it doesn't build. Got this error:
    Severity Code Description Project File Line Suppression State
    Error Could not find android.jar for API level 25. This means the Android SDK platform for API level 25 is not installed. Either install it in the Android SDK Manager (Tools > Android > Android SDK Manager...), or change the Xamarin.Android project to target an API version that is installed. (C:\Program Files (x86)\Android\android-sdk\platforms\android-25\android.jar missing.) Plugin.BLE.Android

  • ColeXColeX Member, Xamarin Team Xamurai
    edited September 2020

    Yes, i'm talking about how to integrate it into Xamarin.iOS ,pls check the steps i provided .

  • dbelldbell Member ✭✭

    I'm confused by above "You don't need to install the plugin" because in your "instructions" SETUP reads "Be sure to install the Plugin.BluetoothLE nuget package..."

    1. I created XAMARIN.IOS project
    2. I followed your "instructions" link and pasted your HOW TO USE - CLIENT BASICS into end of my void ViewDidLoad ()
    3. I Pasted your "permissions in info.plist" (from above) into end of my info.plist
      It fails to build because it doesn't recognize: CrossBleAdapter scanResult and Device

    So, I tried your example .zip from github aritchie/bluetoothle
    1. added "permissions in info.plist" to its info.plist
    2. I opened and ran Plugin.BluetoothLE.sln but got build errors

    I then installed Plugin.BluetoothLE nuget package but the aritchie/bluetoothle

    example still fails to build.

  • ColeXColeX Member, Xamarin Team Xamurai

    Check my sample below and test on real device .

    iOSA.zip 116.5K
  • dbelldbell Member ✭✭
    edited September 2020

    I just ran iOSA, touched "Label" a few times, and got the output below.

    I don't see button entitled "click". (running on iPhone 10, IOS 13.7

    There are nearby bluetooth devices: Macbook, Windows laptop, and iPad mini.
    There is nearby BLE temperature sensor.

    NOTE: The example from Wojciech Kulik runs and detects bluetooth devices...but is buggy (always crashes).

    here is debug output and rebuild-all output (had warnings)...

    Loaded assembly: /private/var/containers/Bundle/Application/C7D99035-3009-4671-9EDC-47A911830EE7/iOSA.app/System.Drawing.Common.dll [External]
    Loaded assembly: /private/var/containers/Bundle/Application/C7D99035-3009-4671-9EDC-47A911830EE7/iOSA.app/System.dll [External]
    Loaded assembly: /private/var/containers/Bundle/Application/C7D99035-3009-4671-9EDC-47A911830EE7/iOSA.app/Xamarin.iOS.dll [External]
    Thread started: #2
    Loaded assembly: /private/var/containers/Bundle/Application/C7D99035-3009-4671-9EDC-47A911830EE7/iOSA.app/System.Core.dll [External]
    Loaded assembly: /private/var/containers/Bundle/Application/C7D99035-3009-4671-9EDC-47A911830EE7/iOSA.app/Plugin.BLE.Abstractions.dll [External]
    Loaded assembly: /private/var/containers/Bundle/Application/C7D99035-3009-4671-9EDC-47A911830EE7/iOSA.app/Plugin.BLE.dll
    Loaded assembly: /private/var/containers/Bundle/Application/C7D99035-3009-4671-9EDC-47A911830EE7/iOSA.app/iOSA.exe
    Thread started: #3
    Thread started: #4
    Thread started: #5
    Thread started: #6
    [0:] The bluetooth state changed to On
    Thread started: #7

    1>------ Rebuild All started: Project: iOSA, Configuration: Debug iPhone ------
    1> Executing SayHello Task to establish a connection to a Mac Server.
    1> Properties: SessionId=d9ed548ae4c0f327e82166b4259d49e8,
    1> ServerPort=51831,
    1> ServerAddress=192.168.7.55,
    1> ServerUser=dbell,
    1> ServerPassword=,
    1> SSHKey=,
    1> SSHPassPhrase=,
    1> AppName=iOSA,
    1> ContinueOnDisconnected=False
    1> Executing SayHello Task to establish a connection to a Mac Server.
    1> Properties: SessionId=d9ed548ae4c0f327e82166b4259d49e8,
    1> ServerPort=51831,
    1> ServerAddress=192.168.7.55,
    1> ServerUser=dbell,
    1> ServerPassword=,
    1> SSHKey=,
    1> SSHPassPhrase=,
    1> AppName=iOSA,
    1> ContinueOnDisconnected=False
    1> iOSA -> C:\PRIMARY\WORK\iOSA ARITCHIE BLE\iOSA\bin\iPhone\Debug\iOSA.exe
    1> Detected signing identity:
    1>
    1> Code Signing Key: "Apple Development: douglas bell (XT7R8ST4AV)" (8513172E519781AA72DD08519137752459D737D9)
    1> Provisioning Profile: "VS: WildCard Development" (2c5ef4ad-59ff-4599-a02f-ac3f721b05aa)
    1> Bundle Id: com.companyname.iOSA
    1> App Id: 4JCD5WXJ7B.com.companyname.iOSA
    1> /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch @/Users/dbell/Library/Caches/Xamarin/mtbs/builds/iOSA/d9ed548ae4c0f327e82166b4259d49e8/obj/iPhone/Debug/device-builds/iphone10.3-13.7/response-file.rsp
    1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(885,3): warning GBD8E3C1A: 'retain (or strong)' attribute on property 'window' does not match the property inherited from 'UIWindowSceneDelegate' [-Wproperty-attribute-mismatch]
    1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(885,3): warning GBD8E3C1A: 'retain (or strong)' attribute on property 'window' does not match the property inherited from 'UIApplicationDelegate' [-Wproperty-attribute-mismatch]
    1> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/dsymutil -num-threads 4 -z -o bin/iPhone/Debug/device-builds/iphone10.3-13.7/iOSA.app.dSYM bin/iPhone/Debug/device-builds/iphone10.3-13.7/iOSA.app/iOSA
    1> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip -i -s obj/iPhone/Debug/device-builds/iphone10.3-13.7/mtouch-symbols.list bin/iPhone/Debug/device-builds/iphone10.3-13.7/iOSA.app/iOSA
    1> /usr/bin/mdimport bin/iPhone/Debug/device-builds/iphone10.3-13.7/iOSA.app/../
    1> /usr/bin/codesign --verify -vvvv "-R=anchor apple generic and certificate 1[field.1.2.840.113635.100.6.2.1] exists and (certificate leaf[field.1.2.840.113635.100.6.1.2] exists or certificate leaf[field.1.2.840.113635.100.6.1.4] exists)" bin/iPhone/Debug/device-builds/iphone10.3-13.7/iOSA.app
    ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

  • dbelldbell Member ✭✭

    I added a button and connected it to you "click" button handler Button_TouchUpInside() and still don't detect anything.

    Loaded assembly: /private/var/containers/Bundle/Application/A1608C80-F753-4EE5-A817-3F645CEDC68E/iOSA.app/System.Drawing.Common.dll [External]
    Loaded assembly: /private/var/containers/Bundle/Application/A1608C80-F753-4EE5-A817-3F645CEDC68E/iOSA.app/System.dll [External]
    Loaded assembly: /private/var/containers/Bundle/Application/A1608C80-F753-4EE5-A817-3F645CEDC68E/iOSA.app/Xamarin.iOS.dll [External]
    Thread started: #2
    Loaded assembly: /private/var/containers/Bundle/Application/A1608C80-F753-4EE5-A817-3F645CEDC68E/iOSA.app/System.Core.dll [External]
    Loaded assembly: /private/var/containers/Bundle/Application/A1608C80-F753-4EE5-A817-3F645CEDC68E/iOSA.app/Plugin.BLE.Abstractions.dll [External]
    Loaded assembly: /private/var/containers/Bundle/Application/A1608C80-F753-4EE5-A817-3F645CEDC68E/iOSA.app/Plugin.BLE.dll
    Loaded assembly: /private/var/containers/Bundle/Application/A1608C80-F753-4EE5-A817-3F645CEDC68E/iOSA.app/iOSA.exe
    Thread started: #3
    Thread started: #4
    Thread started: #5
    Thread started: #6
    [0:] The bluetooth state changed to On
    Thread started: #7
    Thread finished: #4
    Thread finished: #5
    Thread finished: #6
    Thread started: #8
    Thread started: #9
    Thread finished: #3
    Thread started: #10
    Thread finished: #8

  • ColeXColeX Member, Xamarin Team Xamurai

    It is just a simple sample , i just show you how to integrate the plugin into ios project , you need to figure out how it works by yourself .

  • dbelldbell Member ✭✭

    The "BLOB writes" feature looks great because we need to stream data from our embedded BLE peripheral service up to our BLE central client on iOS.

Sign In or Register to comment.