iOS Question BLE scan & connect OK with iPhone 4S, but not with newer iPhones - why?

doodooronron

Member
Licensed User
I have uploaded an app to the app store which will scan and connect to BLE modules with my iPhone 4S (used only for development) without problems.
When a device with a BLE module is powered up, it instantly appears in the device list on the 4S.
However, people with newer iPhones can not see these modules.

The app worked previously with all iPhones, but after a minor update to the app which was not related to the BLE code, later iPhones are now blind to these BLE modules.

The relevant code used is:
UUID:
Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Nav.NavigationBarVisible = False
    Page3.Initialize("Page3")
    Page3.RootPanel.LoadLayout("3")
    NavControl.ShowPage(Page3)
    csu.Initialize
    csu.CallSubDelayedPlus(Me, "AfterSplash", 2000)
 
    Page1.Initialize("Page1")
    Page1.RootPanel.LoadLayout("1")
'    Nav.NavigationBarVisible = True

    Page2.Initialize("Page2")
    Page2.RootPanel.LoadLayout("2")

    manager.Initialize("manager")
    ServiceId = UUID("FFE0")
    ReadChar = UUID("FFE1")
    WriteChar = UUID("FFE2")
    messagesToSend.Initialize
    SetState

    Set_up_page
 
    Timer1.Initialize("Timer1", 50) '1000ms = 1 second and data comes in at 2 Hz
    Timer1.Enabled = False
End Sub

Sub SetState
    btn_upload.Enabled = Connected
    btn_product.Enabled = Connected
    btn_get_settings.Enabled = Connected
    If Connected = False Then
        Connection_status.Color = Colors.RGB(255,0,0)
        Connection_status2.Color = Colors.RGB(255,0,0)
        Connection_status.TextColor = Colors.RGB(255,255,255)
        Connection_status2.TextColor = Colors.RGB(255,255,255)
        Connection_status.Text = "Not connected"
        Connection_status2.Text = "Not connected"
    End If
End Sub

Sub Manager_StateChanged (State As Int)
    If State <> manager.STATE_POWERED_ON Then
        hd.ProgressDialogHide
        hd.ToastMessageShow("Bluetooth is not enabled", True)
    Else
        StartScan
    End If
    SetState
End Sub

Private Sub StartScan
    Try
        Device_MAC = File.ReadString(File.DirDocuments,"MAC.txt")
    Catch
        Log(LastException.Message)
    End Try
    If manager.State = manager.STATE_POWERED_ON Then
        manager.Scan(Array())
    End If
End Sub

Private Sub Manager_DeviceFound (Name As String, DeviceId As String, AdvertisingData As Map, RSSI As Double)
    If Name.Length > 0 Then
    Log($"DeviceFound: ${Name}"$)
    For Each k As String In AdvertisingData.Keys
        Dim v As String = AdvertisingData.Get(k)
        Dim Index As String = v.IndexOf("FFE0") + v.IndexOf("4353")
        If Index = 5 Then
            If DeviceId = Device_MAC Then
                Enable_Connect = True
            End If
            If DevicesListView1.Size > 0 Then
                For I = 0 To DevicesListView1.Size-1
                    DI = DevicesListView1.GetValue (I)
                    If DeviceId = DI Then
                        Duplicate_Flag = 1
                    End If
                Next
            End If

            If Duplicate_Flag = 0 Then
                DevicesListView1.AddTextItem (Name, DeviceId)
                If Row_No < 39 Then
                    Row_No = Row_No + 1
                    Device_name(Row_No) = Name
                End If
            End If
            Duplicate_Flag = 0
            If Enable_Connect = True Then
                Enable_Connect = False
                Device_MAC = DeviceId
                Device_connect
            End If
        End If
    Next
    End If
End Sub

Private Sub Manager_Connected (Services As List)
    Log("Connected to " & Device)
    Connection_status.Text = "Connected to " & Device' & MAC
    Connection_status.Color = Colors.RGB(0,255,0)
    Connection_status.TextColor = Colors.RGB(0,0,0)
    Connection_status2.Text = "Connected to " & Device' & MAC
    Connection_status2.Color = Colors.RGB(0,255,0)
    Connection_status2.TextColor = Colors.RGB(0,0,0)
    Connected = True
    firstRead = True
    manager.ReadData(ServiceId) 'must call once to discover the characteristics
    SetState
    messagesToSend.Clear
'    Nav.NavigationBarVisible = True
    pnl_auto_connect.Visible = False
    NavControl.ShowPage(Page2)
'    btn_product_Click
    buffer = "#Prod" & CRLF
    Log(buffer)
    Dim msg() As Byte = buffer.GetBytes("UTF8")
    For I = 1 To 3
        SendMessage(msg)
    Next
End Sub

Private Sub Manager_DataAvailable (SId As String, Characteristics As Map)
    If firstRead Then
        manager.SetNotify(ServiceId, ReadChar, True)
        firstRead = False
        btn_product_Click
        Return
    End If
    Dim b() As Byte = Characteristics.Get(ReadChar)
    NewMessage(b)
End Sub

Sub SendMessage (msg() As Byte)
    Try
        manager.WriteDataWithResponse(ServiceId, WriteChar, msg)
    Catch
        Log(LastException)
    End Try
End Sub

Private Sub Manager_WriteComplete (Characteristic As String, Status As Int)
    If Connected = False Or messagesToSend.Size = 0 Then Return
    messagesToSend.RemoveAt(0)
    If messagesToSend.Size > 0 Then
        Try
            manager.WriteDataWithResponse(ServiceId, WriteChar, messagesToSend.Get(0))
        Catch
            hd.ToastMessageShow("Device is disconnected", True)
            Log(LastException)
        End Try
    End If
End Sub

Private Sub Save_Device_MAC
    Try
        File.WriteString(File.DirDocuments,"MAC.txt",Device_MAC)
'        Log("We are Inactive" & TAB & modFun.Today & TAB & modFun.Now )
    Catch
        Log("Did not save " & LastException.description)
'        modFun.ShowError("Main_Application_Inactive " & LastException.description)
    End Try
End Sub

Private Sub Manager_Disconnected
    Connected = False
    SetState
    StartScan
End Sub

Can anyone please suggest what might be the issue?
Has something changed in the BLE handling in newer iPhones that breaks this code?

Edit:

After some more digging around, I think it may be the difference in processors. I'll try to compile for 64-bit. More to come.

 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…