Posts

Post not yet marked as solved
3 Replies
129 Views
Hello, I'm looking for a way to detect using NWPathMonitor when the iOS device is connected to a router but not to the internet. As an example a mobile router WiFi without SIM. In settings I'm able to switch the connection to its WiFi, once connected a label below the SSID shows Not connected to the internet. I would like to show the same thing to the user inside my app, but unfortunately I always get the satisfied answer. Am I missing something in configuring NWPathMonitor or reading the answer? final class InternetConnectionMonitor { lazy var internetConnectionStatusPublisher: AnyPublisher<InternetConnectionStatus, Never> = { _internetConnectionStatusSubject .compactMap{ $0 } .eraseToAnyPublisher() }() var lastInternetConnectionStatus: InternetConnectionStatus? { _internetConnectionStatusSubject.value } private let _internetConnectionStatusSubject = CurrentValueSubject<InternetConnectionStatus?, Never>(nil) private let pathMonitor = NWPathMonitor() private let pathMonitorQueue = DispatchQueue(label: "com.xxxxx-network-monitor", qos: .default) init() { startPathMonitoring() } private func startPathMonitoring() { pathMonitor.pathUpdateHandler = { [weak self] path in guard let self else { return } let networkStatus = InternetConnectionStatus(from: path) self._internetConnectionStatusSubject.send(networkStatus) } pathMonitor.start(queue: pathMonitorQueue) } }
Posted
by DrAma78.
Last updated
.
Post not yet marked as solved
2 Replies
213 Views
I added VideoPlayer view inside my project, but I noticed that during loading or with different aspect ratio the default color of this view is black. I would like to change it according to to my app background. Unfortunately using modifiers such as .background or .foregroundColor doesn't seem to change it. Is there a way to customize this color? struct PlayerLooperView: View { private let queuePlayer: AVQueuePlayer! private let playerLooper: AVPlayerLooper! init(url: URL) { let playerItem = AVPlayerItem(url: url) self.queuePlayer = AVQueuePlayer(items: [playerItem]) self.queuePlayer.isMuted = true self.playerLooper = AVPlayerLooper(player: queuePlayer, templateItem: playerItem) self.queuePlayer.play() } var body: some View { VideoPlayer(player: queuePlayer) .disabled(true) .scaledToFit() } }
Posted
by DrAma78.
Last updated
.
Post not yet marked as solved
1 Replies
334 Views
In our app we have the necessity to gather background location after a trigger from a bluetooth event. During the onboarding we ask for authorizedWhenInUse. CLLocationManageris configured like this, and in capabilities we provided the location flag. let cl = CLLocationManager() cl.delegate = self cl.allowsBackgroundLocationUpdates = true cl.desiredAccuracy = kCLLocationAccuracyBestForNavigation According to apple doc or at least what I understood, this should be enough to obtain locations even when the app is in background (and awake). The system allows background updates for apps with either When in Use or Always authorization. If an app isn't running when an update occurs, the system launches the app only if it has Always authorization and uses the significant location change, visits, or region monitoring services. We saw an inconsistent bahviour, the system request to start the location updates after the bluetooth event (we have background capabilities set also for that). In foreground it work always, but in background sometimes it works and sometimes not. When we don't receive a location we usually get a CLError.denied in the func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) method. At this point I don't get the apple doc quote, is it possible to obtain location in background or not with authorizedWhenInUse?
Posted
by DrAma78.
Last updated
.
Post not yet marked as solved
1 Replies
299 Views
I'm experiencing that issue but not on all devices, right now we are able to see a consistent behavior on iPhone 8 with iOS 16.7.5. The NSProcessInfoPowerStateDidChange is never called and the state is never updated during the same app session, it keeps returning the same value. Most weird the systemUptime changes, isLowPowerModeEnabled is the only state that never changes. Tried different approach even polling but the result is always the same. the problem doesn't seems to be in the code, even DataDog SDK (integrated in the same app), that asks the isLowPowerModeEnabled to understand if it could upload logs is affetcted by the same issue. protocol SystemPowerInfoProvider { var isLowPowerModeEnabled: AnyPublisher<Bool, Never> { get } } final class DefaultSystemBatteryOptimizationStateProvider: SystemPowerInfoProvider { var isLowPowerModeEnabled: AnyPublisher<Bool, Never> { _isLowPowerModeEnabled } private lazy var _isLowPowerModeEnabled: AnyPublisher<Bool, Never> = { return Just(ProcessInfo.processInfo.isLowPowerModeEnabled) .merge(with: NotificationCenter.default .publisher(for: Notification.Name.NSProcessInfoPowerStateDidChange) .map { notification -> Bool? in guard let processInfo = notification.object as? ProcessInfo else { return nil } return processInfo.isLowPowerModeEnabled } .compactMap { $0 } ) .eraseToAnyPublisher() }() }
Posted
by DrAma78.
Last updated
.
Post not yet marked as solved
2 Replies
396 Views
In iOS17 this new option has been added in the peripheral connection option CBConnectPeripheralOptionEnableAutoReconnect The documentation states: After a peripheral device connects, this setting enables the system to initiate a connection to the peer device automatically when the link drops. The system uses centralManager(_:didDisconnectPeripheral:timestamp:isReconnecting:error:) to notify the caller about the disconnection. To get the same behavior I used to schedule a new connection after a disconnection depending on the error type. I'm trying to understands if the are more benefits using that flag instead the of "old" way. Can someone clarify that? Best, Andrea
Posted
by DrAma78.
Last updated
.
Post not yet marked as solved
0 Replies
368 Views
Experimenting with Combine, I've seen this behavior but I can't explain why is happening. I'm not trying to achieve nothing in particular so the example doesn't make any sense, I'm just trying to understand why is this happening. let cvsOne = CurrentValueSubject&lt;Int, Never&gt;(0) let cvsTwo = CurrentValueSubject&lt;Int, Never&gt;(5) let canc =  [0,1,2,3].publisher .flatMap { (_) in     return cvsOne } .flatMap { (_) in     return cvsTwo } .sink { (value) in     print("Received \(value)") } From the print statement in the sink I get : Received 5 Received 5 Received 5 Received 5 And it's ok. If I add I send anther value to the cvsTwo, while I'm expecting just one value printed from sink I get the value sent repeated 4 times that is the count of the array elements. cvsTwo.send(10) Received 10 Received 10 Received 10 Received 10 I really do not understand why, attaching print to the publishers flow I see that the array publisher complete with a finish event, but it seems that right after I send the value is triggered again. receive subscription: ([0, 1, 2, 3]) request unlimited receive value: (0) Received 5 receive value: (1) Received 5 receive value: (2) Received 5 receive value: (3) Received 5 receive finished Received 10 Received 10 Received 10 Received 10 Can someone explain that to me?
Posted
by DrAma78.
Last updated
.