I have a singleton observing CTServiceRadioAccessTechnologyDidChange notification from there we unwrap telephonyInfo.serviceCurrentRadioAccessTechnology dictionary with notification.object and then compare to Radio Access Tech friendly names.
We do the above to detect when device changes from 3G to 4G (that is the end goal) but the notification does not consistent update.
When testing on device we switch in Settings -> Cellular -> Cellular Data Options -> Voice & Data between LTE and 3G and at times the notification does not accurate reflect when device switches to 3G or back to LTE, it gets stuck in 3G or LTE.
Below is the code implementation:
func initializeRadioAccessMonitor() {
let carrierType = telephonyInfo.serviceCurrentRadioAccessTechnology
if let radioTech = carrierType?.first?.value {
self.classifyRadioAccessTech(identifier: radioTech)
}
NotificationCenter.default.addObserver(self, selector: #selector(radioAccessChanged), name: .CTServiceRadioAccessTechnologyDidChange, object: nil)
}
@objc func radioAccessChanged(_ notification: Notification) {
let identifier = notification.object as! String
if let radioAccess = telephonyInfo.serviceCurrentRadioAccessTechnology?[identifier] {
self.classifyRadioAccessTech(identifier: radioAccess)
} else {
print("[DEBUG] Error unable to unwrap radio access")
}
}
func classifyRadioAccessTech(identifier: String) {
print("[DEBUG] Radio Access technology: \(identifier)")
if #available(iOS 14.1, *) {
switch identifier {
case CTRadioAccessTechnologyGPRS, CTRadioAccessTechnologyEdge:
radioAccessSpeed = .lowSpeed
case CTRadioAccessTechnologyLTE:
radioAccessSpeed = .highSpeed
case CTRadioAccessTechnologyNRNSA, CTRadioAccessTechnologyNR:
radioAccessSpeed = .superSpeed
default:
radioAccessSpeed = .mediumSpeed
}
} else {
switch identifier {
case CTRadioAccessTechnologyGPRS, CTRadioAccessTechnologyEdge:
radioAccessSpeed = .lowSpeed
case CTRadioAccessTechnologyLTE:
radioAccessSpeed = .highSpeed
default:
radioAccessSpeed = .mediumSpeed
}
}
}
Am I observing the wrong notification or is there a better way to detect changes between 3G and 4G.
System details:
Xcode 13.0
Device details:
iPad 6th Gen LTE - PadOS 15
iPad 8th Gen LTE - PadOS 14.7.1
Post not yet marked as solved
I have referred to this Stack Overflow thread SwiftUI How to Pop to root view - https://stackoverflow.com/questions/57334455/swiftui-how-to-pop-to-root-view
However it doesn't work for my case, of course no answer fits each persons use case perfectly so one always has to modify the answer slightly but of course keeping to the overall outline of the solution.
The solution I went with is use an ObservableObject and set it as an EnvironmentObject of the root view.
The navigation stack grows by 4 views:
RootView().environmentObject(AppSettings.shared)
FirstView()
SecondView()
ThirdView()
FourthView()
The NavigationLink isActive state for the FirstView is defined in AppSettings.shared, all the other states are found in the subsequent view and not in AppSettings.
For example:
FirstView -> SecondView the SecondView isActive state is defined in the ViewModel of the FirstView, and so on and so forth.
What I am trying to achieve is to pop to RootView from the FourthView. So on the FourthView there is an environmentObject variable of type AppSettings (passed down as an EnvironmentObject from RootView) and on button press, toggle RootView -> FirstView isActive state to false.
It toggles but there's no navigation.
However, in the debug console this is the error
Trying to pop to a missing destination at /Library/Caches/com.apple.xbs/Sources/Monoceros/Monoceros-42.24.100/Shared/NavigationBridge_PhoneTV.swift:205
From my understanding toggling that state to false should trigger a navigation back, but in the Stack Overflow thread there was a post to use @State variable from RootView -> FirstView and in the EnvironmentObject have a variable moveToDashbord. Then on the RootView add a .onReceive modifier to listen to moveToDashboard publisher and then trigger @State variable. But again that also results in the same debug console message.
In short all solutions result in a missing destination console message. Is this because the navigation is too deep?
This is an iPad only project, and the navigationView style is set to StackedNavigationStyle.
System Details:
Xcode 11.6
iOS/ PadOS Target 13.0 (so not using SwiftUI 2.0, if that is a thing)
Code examples:
This is the SceneDelegate which sets the AppSettings as system wide EnvironmentObject.
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
let contentView = LoginView().environmentObject(AppSettings.shared)
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: contentView)
self.window = window
window.makeKeyAndVisible()
}
}
This is an example of the navigationLink to the RootView
NavigationLink(destination: RootView().navigationBarBackButtonHidden(true), isActive: self.$loginViewModel.loginSuccess) {
EmptyView()
}
This is an example of navigationLink from RootView -> FirstView:
NavigationLink(destination: FirstView().environmentObject(FirstViewModel()), isActive: self.$appSettings.firstView) {
EmptyView()
}.isDetailLink(false)
Note. I had to change the actual names of the Views for clarification sake.
Post not yet marked as solved
Prior swift versions: Swift 4.0, one was able to pass an inout [Float] array into the vDSP_zvmags functions however, since updating to Swift 4.2 Xcode 10 is complaining about using the [Float]. self.magnitudes = [Float](repeating: 0.0, count: self.halfSize) vDSP_zvmags(&(self.complexBuffer!), 1, &self.magnitudes!, 1, UInt(self.halfSize))The error is on the self.magnitudes parameter:Cannot convert value of type '[Float]' to expected argument type 'Float'Running this code on Xcode 9.4.1 - Swift 4.1 works, but Xcode 10.1 - Swift 4.2 has an error.Could someone please help shed some light on this?
Post not yet marked as solved
Hi,I have come across an issue. The app is very old, written in Objective C and old as in written years and years ago before Swift.The app builds and runs on simulator iOS 11 even, but the problem is the UIWindow has a frame width and height of 640 x 1136. The app looks normal and fine on the iphone 8. But on the iPhone X there is a black bar on the top and a black bar on the bottom of the window. Increasing UIWindow frame height doesn't do anything. Would like to know if anyone else has encountered such an issue and how can this be resolved?Specs:Xcode version 9.4.1