Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macos localName #126

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

macos localName #126

wants to merge 1 commit into from

Conversation

kuyoonjo
Copy link

@kuyoonjo kuyoonjo commented Jan 7, 2025

User description

bugfix macOS localName.


PR Type

Bug fix


Description

  • Fixed the use of localName instead of peripheral.name in filtering devices.

  • Updated scan result to use localName for device name.

  • Improved handling of advertisement data in macOS BLE scanning.


Changes walkthrough 📝

Relevant files
Bug fix
UniversalBlePlugin.swift
Use `localName` for BLE device filtering and results         

darwin/Classes/UniversalBlePlugin.swift

  • Added extraction of localName from advertisement data.
  • Replaced peripheral.name with localName in device filtering.
  • Updated scan result to use localName for device name.
  • +3/-2     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Null Name Handling

    The code does not handle the case when localName is null. This could cause filtering issues since localName is used directly in filterDevice() without null checks.

    let localName = advertisementData[CBAdvertisementDataLocalNameKey] as? String
    let manufacturerData = advertisementData[CBAdvertisementDataManufacturerDataKey] as? Data
    Data Loss

    Using only localName instead of peripheral.name could potentially miss device names in cases where the localName is not advertised but peripheral.name is available.

    name: localName,

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    General
    Implement fallback mechanism for device name when local name is not available in advertisement data

    Add a null coalescing operator to handle cases where localName is nil, falling back
    to peripheral.name as a default value. This ensures device name availability even
    when advertisement data doesn't include a local name.

    darwin/Classes/UniversalBlePlugin.swift [325]

    -let localName = advertisementData[CBAdvertisementDataLocalNameKey] as? String
    +let localName = (advertisementData[CBAdvertisementDataLocalNameKey] as? String) ?? peripheral.name
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    Why: The suggestion provides a robust fallback mechanism for device name resolution, which is critical for maintaining device identification functionality when advertisement data lacks a local name. This directly impacts the reliability of the BLE scanning feature.

    8

    @fotiDim
    Copy link
    Contributor

    fotiDim commented Jan 8, 2025

    @kuyoonjo this breaks name filtering for me. I am trying to scan an iPhone from my mac and I am getting localName as nil while peripheral.name has a value.

    Screenshot 2025-01-08 at 09 37 56

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants