xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.44k stars 508 forks source link

BLE Background Scan not working after update to iOS 17 #20165

Closed BlackWolf4k closed 6 months ago

BlackWolf4k commented 6 months ago

Steps to Reproduce

I am currently building on a iPhone 12 Pro, with iOS 17.3.1

Expected Behavior

I am writing an application to scan in background for BLE devices advertising ( I just need the advertising, not to connect ) Using the same code on the same iPhone with iOS version to iOS 16, and an iPhone 8 with iOS 16.7.2 the code worked ( it was background scanning )

Actual Behavior

After updating my iPhone to iOS 17.3.1 this code stopped working. When exiting the app ( not closing it ), after some seconds the app gets forcibly closed

Environment

Version information Xamarin Version: 16.4.0.18 .NET Version: 7.0.402 ``` using CoreBluetooth; using CoreLocation; using Foundation; using Microsoft.Extensions.Logging; using Xamarin.Forms; [assembly: Dependency(typeof(iOSBleBackgroundBeaconScanService))] namespace BLE_Scan_Background.iOS { public class iOSBleBackgroundBeaconScanService : CBCentralManagerDelegate, IBleBackgroundBeaconScanService { public event IBleBackgroundBeaconScanService.OnDiscoverBleDeviceEventHandler OnDiscoverBleDeviceEvent; private static readonly ILogger? logger = BleMeshConstants.IsLoggingEnable ? DependencyService.Resolve() : null; private CBCentralManager cBCentralManager; /// /// The Uuids to use to scan for the devices /// If looking for any device this should be null /// private CBUUID[] cBUUIDs = new CBUUID[3] { CBUUID.FromString(BleBeaconDevicesEnum.BleBeaconDeviceUuids[0]), CBUUID.FromString(BleBeaconDevicesEnum.BleBeaconDeviceUuids[1]), CBUUID.FromString(BleBeaconDevicesEnum.BleBeaconDeviceUuids[2]), }; private bool isRunning; public iOSBleBackgroundBeaconScanService() { cBCentralManager = new CBCentralManager(this, null); } public void StartBeaconScan(CancellationToken cancellationToken = default) { cancellationToken.Register(() => StopBeaconScan()); // Log some information about the device's ble chip logger?.LogDebug("Ble Status: " + cBCentralManager.State); logger?.LogDebug("Authorizations: " + CBCentralManager.Authorization.ToString()); // Set that a background service is running isRunning = true; // Check if the BleChip is already ON if (cBCentralManager.State == CBCentralManagerState.PoweredOn && cBCentralManager.IsScanning == false) { // Restart the scan cBCentralManager.ScanForPeripherals(cBUUIDs); } } public void StopBeaconScan() { // Stop the scan cBCentralManager?.StopScan(); // cBCentralManager?.Dispose(); // Set that a background process is no longer running isRunning = false; } public bool SupportsExtendedAdv() { return CBCentralManager.SupportsFeatures(CBCentralManagerFeature.ExtendedScanAndConnect); } public override void DiscoveredPeripheral(CBCentralManager central, CBPeripheral peripheral, NSDictionary advertisementData, NSNumber RSSI) { // Log some data about the newly scanned device logger?.LogDebug("Device Name: " + peripheral.Name); //logger?.LogDebug( "Device UUID: " + peripheral.UUID.ToString() ); logger?.LogDebug("Device RSSI: " + RSSI.ToString()); // Maybe add servicedata and localdata of advertisementdata //logger?.LogDebug(advertisementData); // Check the name of the device if (peripheral.Name.isCustomerDevice()) { // Find the "Service Data" key foreach (var key in advertisementData.Keys) { // Look for the ServiceData data if (key.ToString() == "kCBAdvDataManufacturerData") { // Maybe check here if the ServiceData is correct? // The service data in iOS lack of the first 2 bytes // // 1: Data length, 2: Data type // // But Android leaves them and are also used for the parsing of the adv data // // So here are added "hard-code" byte[] advData = new byte[] { 29, 255 }.Concat(((NSData)(advertisementData["kCBAdvDataManufacturerData"])).ToArray()); // Also append the device name because of what written before // But before check if there is a device name foreach (var sKey in advertisementData.Keys) { if (sKey.ToString() == "kCBAdvDataLocalName" && peripheral.Name is not null) { advData = advData.Concat(new byte[] { (byte)(peripheral.Name.Length + 1), 0x09 }).Concat(Encoding.ASCII.GetBytes(peripheral.Name)); // 0x09 is for complete local name } } OnDiscoverBleDeviceEvent?.Invoke(advData, peripheral.Name); logger?.LogDebug("Device Manufacturer Data: " + BitConverter.ToString(advData)); } } // Return an empty event ( this is needed for test scan ) OnDiscoverBleDeviceEvent?.Invoke(null, peripheral.Name); } // This should be started only if the application has gone background cBCentralManager.ScanForPeripherals(cBUUIDs); } public override void UpdatedState(CBCentralManager central) { if (cBCentralManager.State == CBCentralManagerState.PoweredOn) { //cBCentralManager.ScanForPeripherals(cBUUIDs); } else // In this case just stop the scan. Maybe do something else? { cBCentralManager.StopScan(); } } } } ```

Build Logs

I have no particular log as the application gets killed

rolfbjarne commented 6 months ago

When exiting the app ( not closing it ), after some seconds the app gets forcibly closed

Do you get a crash report? Or is anything written to the device console?

microsoft-github-policy-service[bot] commented 6 months ago

Hi @BlackWolf4k. We have added the "need-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

BlackWolf4k commented 6 months ago

Sorry for the delay, I have the following log that shows the opening of the app and what happens when I hide it ( exit the app without closing it forcibly ):

default 09:03:47.800987+0100    BLE_Mesh_Test_.iOS  Evaluating dispatch of UIEvent: 0x2800001a0; type: 0; subtype: 0; backing type: 11; shouldSend: 1; ignoreInteractionEvents: 0, systemGestureStateChange: 0
default 09:03:47.801047+0100    BLE_Mesh_Test_.iOS  Sending UIEvent type: 0; subtype: 0; to windows: 1
default 09:03:47.801105+0100    BLE_Mesh_Test_.iOS  Sending UIEvent type: 0; subtype: 0; to window: <UIWindow: 0x10ceeef40>; contextId: 0xA17C96C6
default 09:03:47.857892+0100    BLE_Mesh_Test_.iOS  Evaluating dispatch of UIEvent: 0x2800001a0; type: 0; subtype: 0; backing type: 11; shouldSend: 1; ignoreInteractionEvents: 0, systemGestureStateChange: 0
default 09:03:47.857922+0100    BLE_Mesh_Test_.iOS  Sending UIEvent type: 0; subtype: 0; to windows: 1
default 09:03:47.857949+0100    BLE_Mesh_Test_.iOS  Sending UIEvent type: 0; subtype: 0; to window: <UIWindow: 0x10ceeef40>; contextId: 0xA17C96C6
default 09:03:47.883840+0100    BLE_Mesh_Test_.iOS  () 22-02-2024 09:03:47.870 [Debug] [iOSBleBackgroundBeaconScanService.cs:151] >  Ble Status: PoweredOn
default 09:03:47.884999+0100    BLE_Mesh_Test_.iOS  () 22-02-2024 09:03:47.884 [Debug] [iOSBleBackgroundBeaconScanService.cs:152] >  Authorizations: AllowedAlways
default 09:03:47.886079+0100    BLE_Mesh_Test_.iOS  Evaluating dispatch of UIEvent: 0x2800001a0; type: 0; subtype: 0; backing type: 11; shouldSend: 0; ignoreInteractionEvents: 0, systemGestureStateChange: 1
default 09:03:50.034082+0100    BLE_Mesh_Test_.iOS  Evaluating dispatch of UIEvent: 0x2800001a0; type: 0; subtype: 0; backing type: 11; shouldSend: 1; ignoreInteractionEvents: 0, systemGestureStateChange: 0
default 09:03:50.034145+0100    BLE_Mesh_Test_.iOS  Sending UIEvent type: 0; subtype: 0; to windows: 1
default 09:03:50.034203+0100    BLE_Mesh_Test_.iOS  Sending UIEvent type: 0; subtype: 0; to window: <UIWindow: 0x10ceeef40>; contextId: 0xA17C96C6
default 09:03:50.065891+0100    BLE_Mesh_Test_.iOS  Evaluating dispatch of UIEvent: 0x2800001a0; type: 0; subtype: 0; backing type: 11; shouldSend: 1; ignoreInteractionEvents: 0, systemGestureStateChange: 0
default 09:03:50.065963+0100    BLE_Mesh_Test_.iOS  Sending UIEvent type: 0; subtype: 0; to windows: 1
default 09:03:50.066021+0100    BLE_Mesh_Test_.iOS  Sending UIEvent type: 0; subtype: 0; to window: <UIWindow: 0x10ceeef40>; contextId: 0xA17C96C6
default 09:03:50.082122+0100    BLE_Mesh_Test_.iOS  Evaluating dispatch of UIEvent: 0x2800001a0; type: 0; subtype: 0; backing type: 11; shouldSend: 1; ignoreInteractionEvents: 0, systemGestureStateChange: 0
default 09:03:50.082302+0100    BLE_Mesh_Test_.iOS  Sending UIEvent type: 0; subtype: 0; to windows: 1
default 09:03:50.082485+0100    BLE_Mesh_Test_.iOS  Sending UIEvent type: 0; subtype: 0; to window: <UIWindow: 0x10ceeef40>; contextId: 0xA17C96C6
default 09:03:50.099349+0100    BLE_Mesh_Test_.iOS  Evaluating dispatch of UIEvent: 0x2800001a0; type: 0; subtype: 0; backing type: 11; shouldSend: 1; ignoreInteractionEvents: 0, systemGestureStateChange: 0
default 09:03:50.099471+0100    BLE_Mesh_Test_.iOS  Sending UIEvent type: 0; subtype: 0; to windows: 1
default 09:03:50.099564+0100    BLE_Mesh_Test_.iOS  Sending UIEvent type: 0; subtype: 0; to window: <UIWindow: 0x10ceeef40>; contextId: 0xA17C96C6
default 09:03:50.114912+0100    BLE_Mesh_Test_.iOS  Evaluating dispatch of UIEvent: 0x2800001a0; type: 0; subtype: 0; backing type: 11; shouldSend: 1; ignoreInteractionEvents: 0, systemGestureStateChange: 0
default 09:03:50.114970+0100    BLE_Mesh_Test_.iOS  Sending UIEvent type: 0; subtype: 0; to windows: 1
default 09:03:50.115016+0100    BLE_Mesh_Test_.iOS  Sending UIEvent type: 0; subtype: 0; to window: <UIWindow: 0x10ceeef40>; contextId: 0xA17C96C6
default 09:03:50.131537+0100    BLE_Mesh_Test_.iOS  Evaluating dispatch of UIEvent: 0x2800001a0; type: 0; subtype: 0; backing type: 11; shouldSend: 1; ignoreInteractionEvents: 0, systemGestureStateChange: 0
default 09:03:50.131639+0100    BLE_Mesh_Test_.iOS  Sending UIEvent type: 0; subtype: 0; to windows: 1
default 09:03:50.131671+0100    BLE_Mesh_Test_.iOS  Sending UIEvent type: 0; subtype: 0; to window: <UIWindow: 0x10ceeef40>; contextId: 0xA17C96C6
default 09:03:50.140213+0100    BLE_Mesh_Test_.iOS  sceneOfRecord: sceneID: sceneID:com.blackwolf.BLE-Mesh-Test--default  persistentID: 67275ECC-9FA0-4F25-8FA4-E241DF02D186
default 09:03:50.140974+0100    BLE_Mesh_Test_.iOS  Deactivation reason added: 0; deactivation reasons: 0 -> 1; animating application lifecycle event: 1
default 09:03:50.168534+0100    BLE_Mesh_Test_.iOS  Deactivation reason added: 12; deactivation reasons: 1 -> 4097; animating application lifecycle event: 1
default 09:03:50.168905+0100    BLE_Mesh_Test_.iOS  Evaluating dispatch of UIEvent: 0x2800001a0; type: 0; subtype: 0; backing type: 11; shouldSend: 1; ignoreInteractionEvents: 0, systemGestureStateChange: 0
default 09:03:50.168962+0100    BLE_Mesh_Test_.iOS  Sending UIEvent type: 0; subtype: 0; to windows: 1
default 09:03:50.169051+0100    BLE_Mesh_Test_.iOS  Sending UIEvent type: 0; subtype: 0; to window: <UIWindow: 0x10ceeef40>; contextId: 0xA17C96C6
default 09:03:50.169152+0100    BLE_Mesh_Test_.iOS  Evaluating dispatch of UIEvent: 0x2800001a0; type: 0; subtype: 0; backing type: 11; shouldSend: 1; ignoreInteractionEvents: 0, systemGestureStateChange: 0
default 09:03:50.169249+0100    BLE_Mesh_Test_.iOS  Sending UIEvent type: 0; subtype: 0; to windows: 1
default 09:03:50.169306+0100    BLE_Mesh_Test_.iOS  Sending UIEvent type: 0; subtype: 0; to window: <UIWindow: 0x10ceeef40>; contextId: 0xA17C96C6
default 09:03:50.219729+0100    BLE_Mesh_Test_.iOS  Evaluating dispatch of UIEvent: 0x2800001a0; type: 0; subtype: 0; backing type: 11; shouldSend: 0; ignoreInteractionEvents: 0, systemGestureStateChange: 0
default 09:03:50.227845+0100    BLE_Mesh_Test_.iOS  sceneOfRecord: sceneID: sceneID:com.blackwolf.BLE-Mesh-Test--default  persistentID: 67275ECC-9FA0-4F25-8FA4-E241DF02D186
default 09:03:50.227895+0100    BLE_Mesh_Test_.iOS  Deactivation reason added: 5; deactivation reasons: 4097 -> 4129; animating application lifecycle event: 1
default 09:03:50.228528+0100    BLE_Mesh_Test_.iOS  sceneOfRecord: sceneID: sceneID:com.blackwolf.BLE-Mesh-Test--default  persistentID: 67275ECC-9FA0-4F25-8FA4-E241DF02D186
default 09:03:50.228559+0100    BLE_Mesh_Test_.iOS  Deactivation reason removed: 0; deactivation reasons: 4129 -> 4128; animating application lifecycle event: 1
default 09:03:50.237541+0100    BLE_Mesh_Test_.iOS  sceneOfRecord: sceneID: sceneID:com.blackwolf.BLE-Mesh-Test--default  persistentID: 67275ECC-9FA0-4F25-8FA4-E241DF02D186
default 09:03:50.237572+0100    BLE_Mesh_Test_.iOS  Deactivation reason added: 0; deactivation reasons: 4128 -> 4129; animating application lifecycle event: 1
default 09:03:50.260726+0100    BLE_Mesh_Test_.iOS  sceneOfRecord: sceneID: sceneID:com.blackwolf.BLE-Mesh-Test--default  persistentID: 67275ECC-9FA0-4F25-8FA4-E241DF02D186
default 09:03:50.260786+0100    BLE_Mesh_Test_.iOS  Scene target of keyboard event deferring environment did change: 0; scene: UIWindowScene: 0x11870d1d0; scene identity: com.apple.frontboard.systemappservices::FBSceneManager:sceneID%3Acom.blackwolf.BLE-Mesh-Test--default
default 09:03:50.855372+0100    BLE_Mesh_Test_.iOS  sceneOfRecord: sceneID: sceneID:com.blackwolf.BLE-Mesh-Test--default  persistentID: 67275ECC-9FA0-4F25-8FA4-E241DF02D186
default 09:03:50.856561+0100    BLE_Mesh_Test_.iOS  Deactivation reason removed: 5; deactivation reasons: 4129 -> 4097; animating application lifecycle event: 1
default 09:03:50.875930+0100    BLE_Mesh_Test_.iOS  Gained inheritances: {(
    <RBSInheritance| environment:(none) name:com.apple.frontboard.visibility origID:32-33-16779 0>
)}
default 09:03:50.875957+0100    BLE_Mesh_Test_.iOS  Received inheritances: {(
    <RBSInheritance| environment:(none) name:com.apple.frontboard.visibility origID:32-33-16779 0>
)}
default 09:03:50.876980+0100    BLE_Mesh_Test_.iOS  Determined "<private>" is a special collection.
default 09:03:50.878011+0100    BLE_Mesh_Test_.iOS  sceneOfRecord: sceneID: sceneID:com.blackwolf.BLE-Mesh-Test--default  persistentID: 67275ECC-9FA0-4F25-8FA4-E241DF02D186
default 09:03:50.878129+0100    BLE_Mesh_Test_.iOS  Deactivation reason added: 11; deactivation reasons: 4097 -> 6145; animating application lifecycle event: 0
default 09:03:50.878344+0100    BLE_Mesh_Test_.iOS  <private>: Will add backgroundTask with taskName: <private>, expirationHandler: (null)
default 09:03:50.878371+0100    BLE_Mesh_Test_.iOS  <private>: Creating new assertion because there is no existing background assertion.
default 09:03:50.878397+0100    BLE_Mesh_Test_.iOS  <private>: Creating new background assertion
default 09:03:50.878495+0100    BLE_Mesh_Test_.iOS  <private>: Created new background assertion <BKSProcessAssertion: 0x28181cf50>
default 09:03:50.880031+0100    BLE_Mesh_Test_.iOS  <private>: Incrementing reference count for background assertion <private>
default 09:03:50.880058+0100    BLE_Mesh_Test_.iOS  <private>: Created background task <private>.
default 09:03:50.880084+0100    BLE_Mesh_Test_.iOS  [0x10ce3e5e0] invalidated on xpc_connection_cancel()
default 09:03:50.880114+0100    BLE_Mesh_Test_.iOS  <private>: Will add backgroundTask with taskName: <private>, expirationHandler: <__NSMallocBlock__: 0x28351fae0>
default 09:03:50.880141+0100    BLE_Mesh_Test_.iOS  <private>: Reusing background assertion <BKSProcessAssertion: 0x28181cf50>
default 09:03:50.880170+0100    BLE_Mesh_Test_.iOS  <private>: Incrementing reference count for background assertion <private>
default 09:03:50.880198+0100    BLE_Mesh_Test_.iOS  <private>: Created background task <private>.
default 09:03:50.880255+0100    BLE_Mesh_Test_.iOS  <private>: Ending background task with UIBackgroundTaskIdentifier: 3
default 09:03:50.880290+0100    BLE_Mesh_Test_.iOS  <private>: Ending task with identifier 3 and description: <private>, _expireHandler: <__NSMallocBlock__: 0x28351fae0>
default 09:03:50.880320+0100    BLE_Mesh_Test_.iOS  <private>: Decrementing reference count for assertion <private> (used by background task with identifier 3: <private>)
default 09:03:50.880644+0100    BLE_Mesh_Test_.iOS  {"msg":"CLLocationManager", "event":"activity", "_cmd":"onDidEnterBackground:", "self":"0x2839600a0", "notification":<private>}
default 09:03:50.881500+0100    BLE_Mesh_Test_.iOS  Deactivation reason removed: 0; deactivation reasons: 6145 -> 6144; animating application lifecycle event: 0
default 09:03:50.882308+0100    BLE_Mesh_Test_.iOS  <private>: Will add backgroundTask with taskName: <private>, expirationHandler: <__NSMallocBlock__: 0x28351f5d0>
default 09:03:50.882364+0100    BLE_Mesh_Test_.iOS  <private>: Reusing background assertion <BKSProcessAssertion: 0x28181cf50>
default 09:03:50.882524+0100    BLE_Mesh_Test_.iOS  <private>: Incrementing reference count for background assertion <private>
default 09:03:50.882610+0100    BLE_Mesh_Test_.iOS  <private>: Created background task <private>.
default 09:03:50.882664+0100    BLE_Mesh_Test_.iOS  Push traits update to screen for new style 2, <UIWindowScene: 0x11870d1d0> (67275ECC-9FA0-4F25-8FA4-E241DF02D186)
default 09:03:50.882778+0100    BLE_Mesh_Test_.iOS  Should not send trait collection or coordinate space update, interface style 2 -> 2, <UIWindowScene: 0x11870d1d0> (67275ECC-9FA0-4F25-8FA4-E241DF02D186)
default 09:03:50.883661+0100    BLE_Mesh_Test_.iOS  Performing snapshot request 0x28352ca50 (type 1)
default 09:03:50.883688+0100    BLE_Mesh_Test_.iOS  [(FBSceneManager):sceneID:com.blackwolf.BLE-Mesh-Test--default] Sending action(s): FBSSceneSnapshotRequestAction
default 09:03:50.900333+0100    BLE_Mesh_Test_.iOS  Received state update for 1233 (app<com.blackwolf.BLE-Mesh-Test-(F98E213E-8076-4199-9686-306C6748A781)>, unknown-NotVisible
default 09:03:50.951718+0100    BLE_Mesh_Test_.iOS  Snapshot request 0x28352ca50 complete
default 09:03:50.952125+0100    BLE_Mesh_Test_.iOS  Push traits update to screen for new style 2, <UIWindowScene: 0x11870d1d0> (67275ECC-9FA0-4F25-8FA4-E241DF02D186)
default 09:03:50.953823+0100    BLE_Mesh_Test_.iOS  Should not send trait collection or coordinate space update, interface style 1 -> 1, <UIWindowScene: 0x11870d1d0> (67275ECC-9FA0-4F25-8FA4-E241DF02D186)
default 09:03:50.972629+0100    BLE_Mesh_Test_.iOS  Performing snapshot request 0x283531350 (type 1)
default 09:03:50.972656+0100    BLE_Mesh_Test_.iOS  [(FBSceneManager):sceneID:com.blackwolf.BLE-Mesh-Test--default] Sending action(s): FBSSceneSnapshotRequestAction
default 09:03:50.973370+0100    BLE_Mesh_Test_.iOS  Lost inheritances: {(
    <RBSInheritance| environment:UIScene:com.apple.frontboard.systemappservices::FBSceneManager:sceneID%3Acom.blackwolf.BLE-Mesh-Test--default name:com.apple.frontboard.visibility origID:32-33-16774 payload 15143490849518878243>,
    <RBSInheritance| environment:(none) name:com.apple.frontboard.visibility origID:32-33-16775 0>
)}
default 09:03:50.973397+0100    BLE_Mesh_Test_.iOS  Lost inheritances: {(
    <RBSInheritance| environment:UIScene:com.apple.frontboard.systemappservices::FBSceneManager:sceneID%3Acom.blackwolf.BLE-Mesh-Test--default name:com.apple.frontboard.visibility origID:32-33-16774 payload 15143490849518878243>,
    <RBSInheritance| environment:(none) name:com.apple.frontboard.visibility origID:32-33-16775 0>
)}
default 09:03:50.977427+0100    BLE_Mesh_Test_.iOS  Received state update for 1233 (app<com.blackwolf.BLE-Mesh-Test-(F98E213E-8076-4199-9686-306C6748A781)>, unknown-NotVisible
default 09:03:51.011794+0100    BLE_Mesh_Test_.iOS  Snapshot request 0x283531350 complete
default 09:03:51.013153+0100    BLE_Mesh_Test_.iOS  <private>: Ending background task with UIBackgroundTaskIdentifier: 4
default 09:03:51.013281+0100    BLE_Mesh_Test_.iOS  <private>: Ending task with identifier 4 and description: <private>, _expireHandler: <__NSMallocBlock__: 0x28351f5d0>
default 09:03:51.013312+0100    BLE_Mesh_Test_.iOS  <private>: Decrementing reference count for assertion <private> (used by background task with identifier 4: <private>)
default 09:03:51.018047+0100    BLE_Mesh_Test_.iOS  Push traits update to screen for new style 2, <UIWindowScene: 0x11870d1d0> (67275ECC-9FA0-4F25-8FA4-E241DF02D186)
default 09:03:51.019001+0100    BLE_Mesh_Test_.iOS  Should not send trait collection or coordinate space update, interface style 2 -> 2, <UIWindowScene: 0x11870d1d0> (67275ECC-9FA0-4F25-8FA4-E241DF02D186)
default 09:03:51.030879+0100    BLE_Mesh_Test_.iOS  [0x281021570] [keyboardFocus] Disabling event deferring records requested: adding recreation reason: detachedContext; for reason: _UIEventDeferringManager: 0x281021570: disabling keyboardFocus: context detached for window: 0x10ceeef40; contextID: 0xA17C96C6
default 09:03:51.031903+0100    BLE_Mesh_Test_.iOS  <private>: Will add backgroundTask with taskName: <private>, expirationHandler: (null)
default 09:03:51.031991+0100    BLE_Mesh_Test_.iOS  <private>: Reusing background assertion <BKSProcessAssertion: 0x28181cf50>
default 09:03:51.032047+0100    BLE_Mesh_Test_.iOS  <private>: Incrementing reference count for background assertion <private>
default 09:03:51.032103+0100    BLE_Mesh_Test_.iOS  <private>: Created background task <private>.
default 09:03:51.032262+0100    BLE_Mesh_Test_.iOS  Target list changed:
default 09:03:51.032321+0100    BLE_Mesh_Test_.iOS  <private>: Ending background task with UIBackgroundTaskIdentifier: 2
default 09:03:51.032377+0100    BLE_Mesh_Test_.iOS  <private>: Ending task with identifier 2 and description: <private>, _expireHandler: (null)
default 09:03:51.032460+0100    BLE_Mesh_Test_.iOS  <private>: Decrementing reference count for assertion <private> (used by background task with identifier 2: <private>)
default 09:03:51.048662+0100    BLE_Mesh_Test_.iOS  <private>: Ending background task with UIBackgroundTaskIdentifier: 5
default 09:03:51.048696+0100    BLE_Mesh_Test_.iOS  <private>: Ending task with identifier 5 and description: <private>, _expireHandler: (null)
default 09:03:51.048729+0100    BLE_Mesh_Test_.iOS  <private>: Decrementing reference count for assertion <private> (used by background task with identifier 5: <private>)
default 09:03:51.048788+0100    BLE_Mesh_Test_.iOS  <private>: Will invalidate assertion: <BKSProcessAssertion: 0x28181cf50> for task identifier: 5
rolfbjarne commented 6 months ago

Unfortunately the log doesn't seem very helpful.

Do you have the bluetooth background execution mode(s) set in your Info.plist? Ref: https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html#:~:text=The%20bluetooth%2Dcentral%20Background%20Execution%20Mode,-When%20an%20app&text=plist%20file%2C%20the%20Core%20Bluetooth,and%20interact%20with%20peripheral%20data.

In any case, this doesn't seem like an issue in our iOS SDK, it's probably a change in iOS itself (since it started happening in iOS 17).

My suggestion would be to create an simple Xcode project and see if you can get that background scanning to work there - if you can get it to work in an Xcode project and not a .NET project, then please attach both the working Xcode project and the failing .NET project and we'll have a look.

microsoft-github-policy-service[bot] commented 6 months ago

Hi @BlackWolf4k. We have added the "need-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

microsoft-github-policy-service[bot] commented 6 months ago

Hi @BlackWolf4k. Due to inactivity, we will be closing this issue. Please feel free to re-open this issue if the issue persists. For enhanced visibility, if over 7 days have passed, please open a new issue and link this issue there. Thank you.