Posts

Post marked as solved
2 Replies
1k Views
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
Posted Last updated
.
Post not yet marked as solved
0 Replies
1.7k Views
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.
Posted Last updated
.