Post

Replies

Boosts

Views

Activity

TestFlight – can't add build to external group
Hi, I'm unable to add the 3rd build of my TestFlight app to any external testing group (but I can for an internal testing group). The 2nd build was successfully added to an external testing group, the 3rd build has the status "Ready to test", and I've expired all other builds. I've also completed the "What to test" section in English (U.K) and English (U.S). Any idea what I might be doing wrong? Thanks!
1
1
431
Jun ’24
accuracy vs RSSI to compare proximity to iBeacons
Hi, I want to see which iBeacon is the closest in a medium-sized radius (I don't care about actual distances). CLBeacon has a proximity property –- but if two iBeacons have the same proximity enum value I'd like to disambiguate using one of CLBeacon's other properties. Should I pick the one with the smallest accuracy, which per Apple's docs should should decrease with distance, or should I pick the one with the highest rssi? Or a mix of both? Thanks in advance!
0
0
434
Aug ’22
Lazy encryption in NWListener
Hi, I'd like to lazily enable encryption on my NWListener. Basically, right now, I've implemented encryption in the NWListener's initialization phase, like so: import CryptoKit import Network extension NWParameters {     // Create parameters for use with Connection and Listener.     convenience init(secret: String, identity: String) {         let tcpOptions = NWProtocolTCP.Options()         tcpOptions.enableKeepalive = true         tcpOptions.keepaliveIdle = 2         let tlsOptions = NWProtocolTLS.Options()         let authenticationKey = SymmetricKey(data: secret.data(using: .utf8)!)         var authenticationCode = HMAC<SHA256>.authenticationCode(for: identity.data(using: .utf8)!, using: authenticationKey)         let authenticationDispatchData = withUnsafeBytes(of: &authenticationCode) { (ptr: UnsafeRawBufferPointer) in             DispatchData(bytes: ptr)         }         let psk = authenticationDispatchData as __DispatchData         var identityData = identity.data(using: .unicode)!         let identityDispatchData = withUnsafeBytes(of: &identityData) { (ptr: UnsafeRawBufferPointer) in             DispatchData(bytes: ptr)         }         let psk_identity = identityDispatchData as __DispatchData sec_protocol_options_add_pre_shared_key( tlsOptions.securityProtocolOptions, psk, psk_identity ) let ciphersuite = tls_ciphersuite_t(rawValue: TLS_PSK_WITH_AES_128_GCM_SHA256)!  sec_protocol_options_append_tls_ciphersuite( tlsOptions.securityProtocolOptions, ciphersuite )         self.init(tls: tlsOptions, tcp: tcpOptions)         self.includePeerToPeer = true         let customProtocol = NWProtocolFramer.Options(definition: TLVMessageProtocol.definition)       self.defaultProtocolStack.applicationProtocols.insert(customProtocol, at: 0)     } } The preshared key (secret) would be a combination of the user's and a peer's CLBeacon major/minor. However, I want to be able to create an NWListener before detecting a peer's CLBeacon, since it's quite a heavy and time-consuming operation. Is there a way to create an NWListener first, and then give it the encryption / preshared key later?
5
0
833
Aug ’21
Get contact info of current user
Hi, I want to display the contact card of the current user with a CNContactViewController. I'm wondering how I can retrieve only the contact info of the current user. I was thinking of filtering through the contacts using NSFullUserName(), but the user could have changed their contact name to something other than their username. Is there a way to get the contact info of just the current user?
0
0
609
Jul ’21
Replace Xcode Project with Swift Package while keeping same repo?
Hi, I'm currently refactoring my Xcode project into a Swift Package with multiple modules, which I combine with a lightweight Xcode project using an XCWorkspace (kind of like Pointfree's isowords). Right now, my Xcode project is hosted on a GitHub repo. However, with this refactoring, it's the Swift Package which will be hosted on GitHub. Can I replace my Xcode project with the Swift Package on the repo, without losing all my history? Will the history of files inside my Xcode project still show up?
0
0
436
Jun ’21
Detect when @EnvironmentObject variable has been initialised inside property wrapper
I'm making a custom property wrapper, and inside of it is an @EnvironmentObject variable. A dummy version of it looks like this: swift @propertyWrapper struct Store: DynamicProperty {     @EnvironmentObject var centralStore: CentralStore     var wrappedValue: CentralStore {         centralStore     }     @State var value: Int = 0     var cancellable: AnyCancellable?     init() {         cancellable = centralStore             .statePublisher             .filter { (n: Int) in n % 2 == 0 }             .sink { [_value] n in _value.wrappedValue = n }     } } When I run this, the program crashes with "Fatal error: No ObservableObject of type CentralStore found." (and I double-checked that I injected it into the view hierarchy with environmentObject(_:)). It seems like the initialisation of the @Store property wrapper is run before centralStore is found - so accessing it leads to a fatalError. Is there a way to detect that my CentralStore environment object has been found, so that I can subscribe to the statePublisher there? (property observers don't seem to work)
1
0
990
May ’21
Should not require a network connection - Swift Student Challenge
Hi, I'm thinking of using Network Framework's peer-to-peer capabilities for this years WWDC 2021 Swift Student Challenge. In the requirements, they say that "your Swift playground should not rely on a network connection". Peer-to-peer doesn't require an actual network connection, but just for the Wi-Fi to be turned on (similar to if I were using MultipeerConnectivity). Does needing Wi-Fi to be toggled on constitute requiring a network connection, even though I don't need a connection per se?
1
0
570
Mar ’21
Network Framework or MultipeerConnectivity?
Hi, I'm wondering if I should choose between Network Framework or MultipeerConnectivity for my peer-to-peer needs. It'll only be between two devices, and won't be with huge amounts of data (some text and an image). Since I'm using SwiftUI, I won't be needing to support older iOS versions. I like the idea of Network Framework - https://developer.apple.com/documentation/network/nwparameters/3020639-includepeertopeer, because: It's newer, so it has a much nicer API which doesn't feel like a thin layer over Objective-C. It lets me define my own transport protocol - https://developer.apple.com/documentation/network/nwprotocolframer, so I have more fine-grain control over how I send, receive, and parse my messages. Meanwhile, MultipeerConnectivity seems to use a weird combination of TCP and UDP which is abstracted away from us. What do you think?
1
0
1.2k
Mar ’21
Convert CALayerGradient to SwiftUI Gradient?
Hi folks! I'm trying to recreate the Instagram app icon gradient in SwiftUI, and came across this code which replicated it perfectly: var view = UILabel() view.frame = CGRect(x: 0, y: 0, width: 1024, height: 1024) view.backgroundColor = .white let layer0 = CALayer() layer0.backgroundColor = UIColor(red: 0.881, green: 0.106, blue: 0.496, alpha: 1).cgColor layer0.bounds = view.bounds layer0.position = view.center view.layer.addSublayer(layer0) let layer1 = CAGradientLayer() layer1.colors = [ &#9;&#9;UIColor(red: 0.259, green: 0.389, blue: 0.874, alpha: 1).cgColor, &#9;&#9;UIColor(red: 0.835, green: 0.208, blue: 0.522, alpha: 0).cgColor ] layer1.locations = [0.04, 1] layer1.startPoint = CGPoint(x: 0.25, y: 0.5) layer1.endPoint = CGPoint(x: 0.75, y: 0.5) layer1.transform = CATransform3DMakeAffineTransform(CGAffineTransform(a: 0.33, b: 0.9, c: -0.9, d: 0.33, tx: 0.56, ty: -0.16)) layer1.bounds = view.bounds.insetBy(dx: -0.5*view.bounds.size.width, dy: -0.5*view.bounds.size.height) layer1.position = view.center view.layer.addSublayer(layer1) // + some more constraints stuff However, as you see, this is using the Core Animation libarary, of which I have absolutely no knowledge, and couldn't possibly translate to SwiftUI Gradient code myself. Maybe I could use UIViewRepresentable? However, I want the resulting view / gradient to conform to ShapeStyle so that I can use it with .fill(_: ShapeStyle) on any Shape I want (I'm actually using a brilliant tool by Quassum Manus to convert SVG code to a SwiftUI Shape). Many thanks!
0
0
921
Jan ’21
Retrieve Device Motion data only once - Core Motion
I'm using Core Motion to see if the phone is facing upwards or downwards, and I only need to retrieve the data once. Here is some of my code: let manager = CMMotionManager() manager.showsDeviceMovementDisplay = true // "Pull data" - since I only need it once manager.deviceMotionUpdateInterval = 1.0 / 60.0 manager.startDeviceMotionUpdates(using: .xMagneticNorthZVertical) // Repeats set to false since I only need it once - but same problem even when set to true self.timer = Timer(fire: Date(), interval: 1.0 / 60.0, repeats: false) { _ in &#9;&#9;print("Timer started") &#9;&#9;if let motionData = manager.deviceMotion?.gravity.z { &#9;&#9;&#9;&#9;print("Successfully unwrapped") &#9;&#9;&#9;&#9;if 0.7...1 ~= motionData { // Facing downwards &#9;&#9;&#9;&#9;&#9;&#9;print("Facing downwards") &#9;&#9;&#9;&#9;&#9;&#9;position = .downwards(motionData) &#9;&#9;&#9;&#9;} else if -1...(-0.7) ~= motionData { // Facing upwards &#9;&#9;&#9;&#9;&#9;&#9;print("Facing upwards") &#9;&#9;&#9;&#9;&#9;&#9;position = .upwards(motionData) &#9;&#9;&#9;&#9;} else { &#9;&#9;&#9;&#9;&#9;&#9;print("Position uknown") &#9;&#9;&#9;&#9;&#9;&#9;position = .unknown &#9;&#9;&#9;&#9;} &#9;&#9;} } RunLoop.current.add(self.timer!, forMode: RunLoop.Mode.default) However, I never reach "Successfully unwrapped". From my attempts to debug, I found that manager.isDeviceMotionActive is never set to true, even though I called startDeviceMotionUpdates(using: .xMagneticNorthZVertical). Why could that be?
1
0
806
Nov ’20
Detect if device is facing up/down horizontally - Core Motion
Hi, I'm trying to create an interaction where an action would be executed when the phone is on top/under another phone horizontally (±35° on all axes), similarly to the two circles which superpose each other when the phone is level in the Measure app. However, from what I've seen, there are many different ways of doing this (especially in relation to reference frames) all with their pros and cons. I was wondering how you would accomplish this efficiently, preferably without the user having to calibrate the phone. I'm already using the proximity sensor, I just want to make sure the phones are vaguely horizontal so the users don't just "high five" each other with their phones, and instead make them put one phone on top of the other face-to-face. Thanks in advance!
0
0
753
Oct ’20
Receive message on WebSocket stream
Hi, I'm using Network Framework to make a peer-to-peer connection between two devices over a WebSocket bytestream. I was wondering, should there be any special logic in my receiveMessage(completion:) code in NWConnection, since I'm using the WebSocket protocol? Here are some snippets of my code: (NWConnection) var connection: NWConnection let parameters = NWParameters.tls parameters.includePeerToPeer = true let websocketOptions = NWProtocolWebSocket.Options() websocketOptions.autoReplyPing = true parameters.defaultProtocolStack.applicationProtocols.insert(websocketOptions, at: 0) let connection = NWConnection(to: endpoint, using: parameters) startConnection() func startConnection() { connection.stateUpdateHandler = { newState in         switch newState { case .ready: log("Connection \(connection) established") self.receiveMessage() // Handle the rest } } Here's my receiveMessage code: func receiveMessage() { connection.receiveMessage { [unowned self] (content, context, isComplete, error) in if let error = error { log("Error while receiving data\(error)") return } if let data = content { didReceiveMessage(data) if let context?.isFinal != nil { didFinishReceiving() } } self.receiveMessage() } } Do WebSocket messages have additional metadata that I need to filter through in my receiveMessage function? Or does content already have just the data I want?
2
0
1.1k
Oct ’20
WebSocket naming convention - Network Framework
Hi, I'm using Network Framework to make a peer-to-peer WebSocket connection between two devices. I'm currently setting up my Listener: class TapListener {     let userID: UserID     init(userID: UserID) {         self.userID = userID         startListening()     }     func startListening() {         do {             let parameters = NWParameters.tls             parameters.includePeerToPeer = true             let webSocketOptions = NWProtocolWebSocket.Options()             webSocketOptions.autoReplyPing = true            parameters.defaultProtocolStack.applicationProtocols.insert(webSocketOptions, at: 0)             let listener = try NWListener(using: parameters)             listener.service = NWListener.Service(type: "_tapit._websocket",                                                   domain: "local",                                                   txtRecord: userID.data()) (rest of code)         } catch {             log("Failed to create listener")             abort()         }     } } I was wondering, should the type of the service be "_tapit._websocket" or "_tapit._tcp" I found very little documentation regarding naming conventions with WebSocket, so I'm asking just to make sure! P.S: Is it necessary for me to specify the domain? Thanks in advance!
1
0
1.2k
Oct ’20
Network Framework peer-to-peer + Bluetooth Proximity
Hello there, I'm currently working on the networking side of my SwiftUI app, and my question is, how would I go about making both devices both NWBrowsers and NWListeners at the same time? The first device to find an NWListener (through Bluetooth proximity and NWBrowser) would tell the other to cancel their NWBrowser, effectively becoming the server while the first one stays the client. Then, when the data transfer from the server to the client is done, they would switch places, so that the first phone can transfer their data to the second. I don't have much experience in Networking, and the lack of explanative documentation for the Network Framework means the learning curve is very steep. Do I even need to do the server-client switching, or will NWConnection take care of that? Maybe a custom framing protocol, like what Apple showed in their WWDC presentation - https://developer.apple.com/videos/play/wwdc2019/713/?time=368? I would be grateful for a few pointers or what direction I should take. P.S: I know MultipeerConnectivity fits my needs and abstracts away many of the technicalities in networking, but it's unsupported (compared to Network) and doesn't offer the level of customisation that I'll need in the future (especially for Bluetooth proximity, which is how, when an NWListener gets very close, NWBrowser knows it must connect to it).
3
0
1.8k
Oct ’20