I think I know the answer after speaking with ChatGPT but I figured I'd ask here in case someone found some hack. What I'm trying to do is play music through two bluetooth speakers using any streaming platform? I have tried connecting to two speakers through the OS and then tried setting up an AVAudioSession and messing with the options and Categories to achieve this but have been unsuccessful, and have even tried seeing if it could at least be done with playing music from the app I've created myself with a .mp3 file which also has been unsuccessful. I've read there possibly could be something with hardware/firmware that could be done to achieve this for iOS but I'm trying to see what could be done app side first. Samsung phones have the ability to dual-stream, so is there really no way to achieve the same on iOS?
Post
Replies
Boosts
Views
Activity
I have encountered a strange behavior these past couple weeks while dealing with Bluetooth, mostly because my code hasn't changed in over 6 months (maybe it was not working before and now it's correct, who knows). Essentially, when i pair with a bluetooth device for the first time, the onchange has stopped firing. I can post more exact code of the view but I didn't think it was necessary but after you select the device you want to connect to (for the first time) you get asked by the OS to pair. After successful connection, we read information from the device (the Profiles). Once I get that information, i set dataGathered to true which triggers .onChange and I can navigate. However, with this initial connection/pairing the .onChange is never triggered, but i know i'm getting my dataGathered set to true because my print is being set. Subsequent connections do cause .onChange to be triggered with 0 profiles and with many profiles. This code hasn't changed in months so i'm not sure if there's SwiftUI bug that's sprung up or what, or if there's an inherint issue with what i was doing and it's only now being caught.
struct DeviceSearchView: View {
@StateObject var connectedManager: Manager = Manager()
@StateObject var bluetoothListener: Listener = BluetoothListener()
var body: some View {
body
.onChange(self.bluetoothListener.connectedDevice) { device in
device.getData()
}
.onChange(self.connectedManager.dataGathered) { dataGathered in
// determine navigation
}
}
}
Manager Object
final class Manager: ObservedObject, BTDelegate, Identifiable /*i've tried adding/switching with Equatable but no change*/ {
@Published var dataGathered: Bool = false
@Published var profileList: Profile = [Profile]()
@Published var index: Int = 0
func updatedProfile(list: NSArray, selectedIndex: Int) {
print("profiles are in fact here")
var newList = [Profile]()
for element in list {
if let profile = element as? B50Profile {
print("\(profile.name)")
if !newList.contains(profile){
newList.append(profile)
}
}
}
self.profileList = newList
self.index = selectedIndex
self.dataGathered = true
print("data gathered is \(self.dataGathered)"
}
}
On versions iOS 14+, my app which is connected by bluetooth to another device will become slow to write information. This isn't a couple hundred ms or a second or two, but upwards of 10 minutes for it to be sent and then 400 ms to be processed by the device and send its response back. I've confirmed with PacketLogger and with system logs that what commands we are sending with .writeValue are taking over 10 minutes.
This is the timestamp of when we are writing to the device
This is the PacketLogger timestamp of when the phone actually wrote to our device
This doesn't occur immediately, but is intermittent and once it does begin to occur, there's nothing to do to get out of it except for connecting once again to the device. Which, overtime, the issue begins to spring up again. So why is it taking 13 minutes for it to go through the phone and finally being sent?
I've implemented a navigation stack that appends the next view's view model so that the appending and .navigationDestination looks like the below. Whenever I press the continue button to add the viewModel to the path in the ContentView (the child of BumperScreen and the second in the path), the app just stops. I tried isolating the problem with a test project using the same methodology for navigation and have been able to navigate several views, almost infinitely. I cannot replicate this issue and am having a hard time understanding why one is working, and not the other.
struct BumperScreen: View {
@State private var path = NavigationPath()
@StateObject var viewModel: BumperScreenViewModel
@StateObject var sheetManager = SheetManager()
init(viewModel: @autoclosure @escaping () -> BumperScreenViewModel) {
self._viewModel = .init(wrappedValue: viewModel())
}
var body: some View {
if isDoneOnboarding {
HomeView()
.environmentObject(sheetManager)
} else {
NavigationStack(path: $path) {
ZStack {
Color(.Gold)
.ignoresSafeArea()
VStack {
if show {
Spacer()
loadAnimation
.frame(width: 150, height: 150)
.task {
try? await viewModel.getDataFromAPI()
try? await Task.sleep(for: Duration.seconds(1))
path.append(ContentViewViewModel())
doneLoading.toggle()
show.toggle()
}
Spacer()
} else if doneLoading {
EmptyView()
} else {
launchAnimation
}
}
.navigationDestination(for: ContentViewViewModel.self) { model in
ContentView(viewModel: model, path: $path)
.environmentObject(sheetManager)
}
}
}
}
}
}
Which leads the user to the second view
struct ContentView: View {
@EnvironmentObject var sheetManager: SheetManager
@StateObject var viewModel: ContentViewViewModel
@Binding var path: NavigationPath
var body: some View {
ZStack {
Color(.trulliGold)
.ignoresSafeArea()
VStack {
Spacer()
headerStatement
Spacer()
VStack {
privacyPolicy
bluetoothPolicy
locationsPolicy
notificationsPolicy
apprunningPolicy
}
Spacer()
Spacer()
continueButton
}
}
.popup(with: sheetManager)
.navigationBarBackButtonHidden()
}
var continueButton: some View {
Button(action: {
print("pressed")
path.append(WelcomeScreenViewViewModel())
}) {
Text("CONTINUE")
}
.navigationDestination(for: WelcomeScreenViewViewModel.self) { model in
WelcomeScreenView(viewModel: model, path: $path)
}
}
}
Which goes to
struct WelcomeScreenView: View {
@StateObject var viewModel: WelcomeScreenViewViewModel
@Binding var path: NavigationPath
var body: some View {
ZStack {
Color(.trulliGold)
.ignoresSafeArea()
VStack(alignment: .center, spacing: 8) {
header
Spacer()
tabView
Spacer()
Spacer()
nextButton
closeButton
}
}
.navigationDestination(for: SetupGuideSpeakerSearchViewViewModel.self) { model in
SetupGuideSpeakerSearchView(viewModel: model, path: $path )
}
.navigationBarBackButtonHidden()
}
}
I've tried isolating the issue to a debug project and have been able to navigate several views therein with no issue. debug project