Hi,
I am currently running into a strange issue. I am talking to an external device which can send multiple sequential warnings.
I am using the new
view.alert(title, isPresented, actions, message) modifier.
Sometimes it happens that the external message becomes irrelevant in which case I clear the isPresented Binding to remove the Alert and present the next one if there is one.
I use 2 ObjervableObjects - one that contains the isPresented flag and one for the content of the Message. If I reset isPresented, update the content ObservableObject and set isPresented again, the Alert window cannot get dismissid by setting isPresented to false again. The Alert just stays along and the new Alert does not get presented. (although somehow the UI believes it is presenting a new Alert)
I found that I need to wait a bit after clearing iPresented and do an DispatchQueue.main.asyncAfter to set my iPresented flag - to allow the Alert window to vanish and the views to update.
If there is a timing problem with dismissing the .alert - shouldn't there be a completion handler for the alert - obviously putting in a random delay seems hacky...?
Best,
Michael
Post
Replies
Boosts
Views
Activity
I do have a SwiftUI view with a model and lately when I run the iOS App on Mac as "designed for iPAD" it crashes.
The view uses a LazyVGrid - I suspect that is the issue?
My code works on iPad and iPhone but crashes on Mac when elements from the LazyVGrid are being removed from the ObservableObject driving the view.
Any recommendations what I could do about this? I currently have no idea about where to start as I cannot dig further and the stack trace does not contain any of my code...
Cheers,
Michael
here is what I get in the output:
*** First throw call stack:
(
0 CoreFoundation 0x000000019b28c418 __exceptionPreprocess + 176
1 libobjc.A.dylib 0x000000019add6ea8 objc_exception_throw + 60
2 Foundation 0x000000019c1cca60 -[NSCalendarDate initWithCoder:] + 0
3 UIKitCore 0x00000001c5137cfc -[UICollectionViewData indexPathForItemAtGlobalIndex:] + 172
4 UIKitCore 0x00000001c5429d74 __114-[UICollectionView _createAndAppendViewAnimationsForInsertsInCurrentUpdate:appearingAnimations:newSubviewManager:]_block_invoke + 76
5 UIKitCore 0x00000001c5429c78 -[UICollectionView _createAndAppendViewAnimationsForInsertsInCurrentUpdate:appearingAnimations:newSubviewManager:] + 1304
6 UIKitCore 0x00000001c5428ba8 -[UICollectionView _viewAnimationsForCurrentUpdateWithCollectionViewAnimator:] + 244
7 UIKitCore 0x00000001c542ee84 __102-[UICollectionView _updateWithItems:tentativelyForReordering:propertyAnimator:collectionViewAnimator:]_block_invoke.748 + 180
8 UIKitCore 0x00000001c5011034 +[UIView(Animation) performWithoutAnimation:] + 76
9 UIKitCore 0x00000001c542e3bc -[UICollectionView _updateWithItems:tentativelyForReordering:propertyAnimator:collectionViewAnimator:] + 1388
10 UIKitCore 0x00000001c5428278 -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:collectionViewAnimator:] + 8608
11 UIKitCore 0x00000001c5430b98 -[UICollectionView _performBatchUpdates:completion:invalidationContext:tentativelyForReordering:animator:animationHandler:] + 512
12 SwiftUI 0x00000001daf7aaec OUTLINED_FUNCTION_7 + 10996
13 SwiftUI 0x00000001db151160 OUTLINED_FUNCTION_2 + 52
14 SwiftUI 0x00000001db151188 OUTLINED_FUNCTION_2 + 92
15 UIKitCore 0x00000001c5011034 +[UIView(Animation) performWithoutAnimation:] + 76
...
2022-11-22 15:03:07.461972+0100 CameraCompanionBETA[3997:41963] [General] An uncaught exception was raised
2022-11-22 15:03:07.462026+0100 CameraCompanionBETA[3997:41963] [General] request for index path for global index 4 when there are only 4 items in the collection view
2022-11-22 15:03:07.462092+0100 CameraCompanionBETA[3997:41963] [General] (
0 CoreFoundation 0x000000019b28c418 __exceptionPreprocess + 176
1 libobjc.A.dylib 0x000000019add6ea8 objc_exception_throw + 60
2 Foundation 0x000000019c1cca60 -[NSCalendarDate initWithCoder:] + 0
3 UIKitCore 0x00000001c5137cfc -[UICollectionViewData indexPathForItemAtGlobalIndex:] + 172
4 UIKitCore 0x00000001c5429d74 __114-[UICollectionView _createAndAppendViewAnimationsForInsertsInCurrentUpdate:appearingAnimations:newSubviewManager:]_block_invoke + 76
5 UIKitCore 0x00000001c5429c78 -[UICollectionView _createAndAppendViewAnimationsForInsertsInCurrentUpdate:appearingAnimations:newSubviewManager:] + 1304
6 UIKitCore 0x00000001c5428ba8 -[UICollectionView _viewAnimationsForCurrentUpdateWithCollectionViewAnimator:] + 244
7 UIKitCore 0x00000001c542ee84 __102-[UICollectionView _updateWithItems:tentativelyForReordering:propertyAnimator:collectionViewAnimator:]_block_invoke.748 + 180
8 UIKitCore 0x00000001c5011034 +[UIView(Animation) performWithoutAnimation:] + 76
9 UIKitCore 0x00000001c542e3bc -[UICollectionView _updateWithItems:tentativelyForReordering:propertyAnimator:collectionViewAnimator:] + 1388
10 UIKitCore 0x00000001c5428278 -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:collectionViewAnimator:] + 8608
11 UIKitCore 0x00000001c5430b98 -[UICollectionView _performBatchUpdates:completion:invalidationContext:tentativelyForReordering:animator:animationHandler:] + 512
12 SwiftUI 0x00000001daf7aaec OUTLINED_FUNCTION_7 + 10996
13 SwiftUI 0x00000001db151160 OUTLINED_FUNCTION_2 + 52
14 SwiftUI 0x00000001db151188 OUTLINED_FUNCTION_2 + 92
15 UIKitCore 0x00000001c5011034 +[UIView(Animation) performWithoutAnimation:] + 76
16 SwiftUI 0x00000001daf7a934 OUTLINED_FUNCTION_7 + 10556
17 SwiftUI 0x00000001da9da4b0 OUTLINED_FUNCTION_10 + 77892
...
TestCombineLatest.log
Hello Eskimo, check the example below...
If the documentation for Publishers.Combine would be correct, it would always announce an unlimited demand to the upstream publishers - and it doesn't.
There also seems to be a bug if downstream requests a demand of .max(1).
Somehow I am pretty puzzled by this bug... seems there is just limited unit testing for an API? Or is there something I don't understand?
I have filed a radar: FB10446601 - wondering if anyone will look at it...
Testcase output attached.
import Foundation
import Combine
import XCTest
class TestCombineLatest:XCTestCase {
func testCombineLatest() {
let latest1 = PassthroughSubject<Int,Never>()
let latest2 = PassthroughSubject<Int,Never>()
var result:[[Int]] = []
var subscription:Subscription?
let subscriber = AnySubscriber<(Int,Int),Never>(
receiveSubscription: {sub in
subscription = sub
sub.request(.max(1))
// replace with sup.request(.unlimited) and the test case succeeds.
},
receiveValue: { (v1,v2) in
result.append([v1,v2])
return .max(1)
},
receiveCompletion: {_ in}
)
let publisher = Publishers.CombineLatest(latest1.print("Latest1"), latest2.print("Latest2"))
.print("CombineLatest")
publisher
.subscribe(subscriber)
latest1.send(1)
latest2.send(1)
latest1.send(2) //<- has no effect...
latest2.send(2)
latest1.send(completion: .finished)
latest2.send(completion: .finished)
print("Result is:\(result)")
XCTAssertEqual(result, [[1,1], [2,1], [2,2] ])
}}
Hi Quinn,
I am developing an app that connects to a local device via Wifi or Ethernet.
I am using tcp over Network.framework for the communication.
My network connector is configured as such for iOS:
let tcp_params = NWParameters.tcp
tcp_params.preferNoProxies = true
tcp_params.acceptLocalOnly = true
tcp_params.prohibitedInterfaceTypes = [.cellular]
So what happens is that everything is fine as long as both the iPhone and the device are connected to an AccesPoint. But there is another option where the device acts as AccessPoint and you can join that network straight. The device, since it has no connection to the internet, does not offer a default route - so that any client devices can still use cellular network to access the internet.
What happens though is that I cannot get a connection to that device in case cellular data is on.
The state handler shows the following error message:
lC3 MINI-20001._cap._tcp.local. tcp, no cellular, prefer no proxy, attribution: developer, path unsatisfied (Denied over cellular interface), interface: pdp_ip0[lte], ipv4, ipv6, expensive]
As soon as I disable cellular data, everything works fine.
Is there any way to get around this? There must be cause Safari can actually connect to the device even with cellular data on.
I have played with various ways to configure the NWParameters, but no luck.
Maybe you got the magic?
Cheers,
Michael
So here is a little piece of code that sums up a problem I cannot figure out atm.
In the code below I add and remove entries to a dictionary keyed by an Enum.
What I would expect is that every time I add an item a new random number is being generated in the Element view and displayed.
What happens is that for every same Ident the same random number shows up - event though the ForEach loop has had a state where that Ident key was not in the dictionary any more.
It appears as if ForEach does not purge the @State vars of the Element views that are not present any more, but reuses them when a new entry to the dictionary is added with the same Ident.
Is this expected behavior? What am I doing wrong?
Here is the code:
import Foundation
import SwiftUI
enum Ident:Int, Comparable, CaseIterable {
case one=1, two, three, four
static func < (lhs: Ident, rhs: Ident) -> Bool {
lhs.rawValue < rhs.rawValue
}
}
extension Dictionary where Key == Ident,Value== String {
var asSortedArray:Array<(Ident,Value)> {
Array(self).sorted(by: { $0.key < $1.key })
}
var nextKey:Ident? {
if self.isEmpty {
return .one
}
else {
return Array(Set(Ident.allCases).subtracting(Set(self.keys))).sorted().first
}
}
}
struct ContentView: View {
@State var dictionary:[Ident:String] = [:]
var body: some View {
Form {
Section {
ForEach(dictionary.asSortedArray, id: \.0) { (ident, text) in
Element(dictionary: $dictionary, ident: ident, text: text)
}
}
Section {
Button(action: {
if let nextIdent = dictionary.nextKey {
dictionary[nextIdent] = "Something"
}
}, label: {
Text("Add one")
})
}
}
}
}
struct Element:View {
@Binding var dictionary:[Ident:String]
var ident:Ident
var text:String
@State var random:Int = Int.random(in: 0...1000)
var body: some View {
HStack {
Text(String(ident.rawValue))
Text(String(random))
Button(action: {
dictionary.removeValue(forKey: ident)
}, label: {
Text("Delete me.")
})
Spacer()
}
}
}
Hi,
I am trying to talk to our cameras (local Wifi, no Internet access, no contact to any authority) and so far we used our own APIs but also regular http calls to do so.
It seems with the latest iOS update that is not possible any more (even on a low level)? None of the browsers (firefox and chrome) works any more and also the parts of the app which used http requests.
For us this would mean to upgrade everything to https (including all the certificate management) - which is tricky as we don't necessarily have connection to an authority at the time (it is a camera and used in places with no Internet) and certificates need to be managed by the user locally through exceptions). Unfortunately our products have quite a lifetime - so we'd need to change software for products which are 5-8 years old...
@eskimo Can you confirm?
Cheers,
Michael
Hi,
I have an iOS/watchOS app that talks to an external device (a camera) on a proprietary tcp protocol via Network.framework.
With the latest version we have migrated communications to the watch so that the Watch talks to the camera directly (previously it did through the watch) - and I was hoping that we could get to a state where the iOS app is only required for configuration of the connection (logon info etc), which is much easier done on iOS.
So far everything works great - except that the iWatch looses Wifi connectivity as soon as the iPhone is out of range or joins another network.
I have configured the iWatch to join the cameras network - but still, as soon as the phone looses the network the connection is gone.
The idea really is to enable the user to work with the camera hands free with no need to use the phone.
The control center indicates that I am connected to Wifi, but Network.framework does not seem to connect.
Is there anything I need to configure on the tcp connection in Network.framework to have it talk to the device directly without checking the phone? Or is an independent connection of the iWatch to a network and tcp connection not possible (I thought with stand alone watch app this should work?)
As always - thanks for any hints or information!
Best,
Michael