Post

Replies

Boosts

Views

Activity

iOS: Bluetooth name caching and cannot connect to BLE
We are developing an application related to BLE connection to the speaker. Currently when doing connect BLE and triggering the bonding process to the speaker, we are experiencing the following phenomenon: Scan BLE and discover Speaker 1 Peripheral: <CBPeripheral: 0x283f50aa0, identifier = 76D8D754-3F0F-82CD-18F2-37BAA4AFB638, name = (mac-address of speaker 1), mtu = 0, state = disconnected> - kCBAdvDataManufacturerData: (advertising data of device 1) Implement BLE connect and trigger bonding process to the speaker (pair): speaker 1 is connected to BLE and BL-classic at the same time. After pairing and connecting, the peripheral's name has changed to the one we see in the Bluetooth system. Turn off speaker 1 and turn on speaker 2. We scan and discover speaker 2: Peripheral: <CBPeripheral: 0x283f58fa0, identifier = E290BB25-9046-FF4A-010D-CE5F2DA87527, name = (name of speaker 1), mtu = 0, state = disconnected> - kCBAdvDataManufacturerData: (advertising data of device 2) Implement BLE connect and trigger bonding process to the speaker (pair): we can't connect BLE to speaker 2 and always return to delegate centralManager(_:didDisconnectPeripheral:error:). => You can see we have scanned 2 speakers with different kCBAdvDataManufacturerData but somehow the 2nd peripheral shows the same name as the 1st peripheral and we can't connect to the 2nd peripheral. It seems as though the iOS device is caching the peripheral information. Does anyone know if there is a way to clear the cache or refresh to get the current/valid status of the device from the app side?
0
0
1.2k
Apr ’23
OSLog is not working when launching the app with Siri.
I am implementing AppIntent into my application as follows: // MARK: - SceneDelegate var window: UIWindow? private var observer: NSObjectProtocol? func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { guard let windowScene = (scene as? UIWindowScene) else { return } // Setup window window = UIWindow(windowScene: windowScene) let viewController = ViewController() window?.rootViewController = viewController window?.makeKeyAndVisible() setupUserDefaultsObserver() checkShortcutLaunch() } private func setupUserDefaultsObserver() { // use NotificationCenter to receive notifications. NotificationCenter.default.addObserver( forName: NSNotification.Name("ShortcutTriggered"), object: nil, queue: .main ) { notification in if let userInfo = notification.userInfo, let appName = userInfo["appName"] as? String { print("📱 Notification received - app is launched: \(appName)") } } } private func checkShortcutLaunch() { if let appName = UserDefaults.standard.string(forKey: "shortcutAppName") { print("🚀 App is opened from a Shortcut with the app name: \(appName)") } } func sceneDidDisconnect(_ scene: UIScene) { if let observer = observer { NotificationCenter.default.removeObserver(observer) } } } // MARK: - App Intent struct StartAppIntent: AppIntent { static var title: LocalizedStringResource = "Start App" static var description = IntentDescription("Launch the application with the command") static var openAppWhenRun: Bool = true @MainActor func perform() async throws -> some IntentResult { UserDefaults.standard.set("appName", forKey: "shortcutAppName") UserDefaults.standard.set(Date(), forKey: "shortcutTimestamp") return .result() } } // MARK: - App Shortcuts Provider struct AppShortcutsProvider: AppShortcutsProvider { static var appShortcuts: [AppShortcut] { AppShortcut( intent: StartAppIntent(), phrases: [ "let start \(.applicationName)", ], shortTitle: "Start App", systemImageName: "play.circle.fill" ) } } the app works fine when starting with shortcut. but when starting with siri it seems like the log is not printed out, i tried adding a code that shows a dialog when receiving a notification from userdefault but it still shows the dialog, it seems like the problem here is when starting with siri there is a problem with printing the log. I tried sleep 0.5s in the perform function and the log was printed out normally try? await Task.sleep(nanoseconds: 500_000_000) // 0.5 seconds I have consulted some topics and they said that when using Siri, Intent is running completely separately and only returns the result to Siri, never entering the Main App. But when set openAppWhenRun to true, it must enter the main app, right? Is there any way to find the cause and completely fix this problem?
6
0
153
1w