Posts

Post not yet marked as solved
0 Replies
269 Views
I'm trying to get my head around Swift and have promised myself my next app will be a SwiftUI appp... I am trying hard to update my thinking away from C style pointers and so on, but here's something thats got me stumped so far. My app will communicate with an embedded network device. The device sends me packets of data with a well-defined header followed by an optional payload of data bytes. In C (on the device) the header is defined like this: typedef struct _MSG_TYPE { uint16_t sig; uint16_t len; // Total length of message, include header and playload; uint16_t type; uint32_t data; // 32 Bits of data. } MSG_t; And my app will respond with messages using the same type of header. Since I'm trying to do this in Swift I somehow need to get my C-type structs in-and-out of Swift style Data types. Here's my receive function: private func receive_data() { nwConnection.receive(minimumIncompleteLength: 1, maximumLength: 65536) { (data, _, isComplete, error) in if let data = data, !data.isEmpty { print("connection did receive, data: \(data as NSData) ") if let msgCallback = self.messageDeliveryCallback { msgCallback(data) } } if isComplete { self.connectionDidEnd() } else if let error = error { self.connectionDidFail(error: error) } else { self.receive_data() } } } And the callback which it calls looks like this: func messageDelivery(message: Data?) { if let data = message, !data.isEmpty {   } } So my questions is. In the callback - how do I get the data from the Data type into one of my MSG_t structs? Or is there a better way to extract the equivalent bytes? And for sending message back to the client, how do I get one of my MSG_t structs into a swift Data type? I looked at using something like: var getInfoMsg = MSG_t(sig: UInt16(MSG_SIG), len: UInt16(MemoryLayout<MSG_t>.size), type: UInt16(MSG_TYPE_GET_INFO), data: 0) var newData = Data(bytes: UnsafeRawPointer(getInfoMsg), count: Int(getInfoMsg.len)) But that doesn't seem right and give an error: No exact matches in call to initializer  Hah. Sorry if this is a ****** question - like I say, trying to learn swift, but I'm old and slow!! So how do I convert to/from my MSG_t to Data in swift?
Posted Last updated
.
Post not yet marked as solved
0 Replies
288 Views
I have some .mp4 files recorded on Full-HD Video cameras at 1080x1920 25p When I play these files in QuickTime they play perfectly. If I use QuickTime to trim the files and save the results - again they play perfectly. If I import these into a 1080x1920,25p project in FCPX and trim them, then 'share' to Apple 1080 - the audio has pops and clicks.
Posted Last updated
.
Post not yet marked as solved
2 Replies
233 Views
These forums are really bordering on un-usable. I'm not trying to give the team who built them a hrad time - but we are developers, these are developer forums, and we're trying to help each other. But simple things like not being able to embed an image are essential for peer to peer developer forums. Can someone at apple please state what the thinking is? I would much rather post here than in StackOverflow - but there doesn't seem to be any real valuable developers left here now. I'd have thought that Apple would want to encourage their developers to meet here, as they (Apple) could learn so much about what is going on in the developer community without having to scrape it from other third party sites. I'm at a loss as to how we are supposed to help each other when you can't post links, embed images or even reply to a reply.
Posted Last updated
.
Post marked as solved
1 Replies
782 Views
In previous versions of Xcode, including 11.x, there used to be a toolbar button to show/hide the debug area. I found this to be extremely useful. However it is no longer present in 12.0 ☹️ You can still access it with SHIFT+⌘+Y, but can we please have the button back! (FB: FB8723138)edit* Spelling and grandma.
Posted Last updated
.
Post marked as solved
5 Replies
435 Views
An app I'm doing requires a big round segmented button in the middle. Like this... What! We are not allowed to attach or embed images? OK you can see an examaple here: h t t p s : / / w p h o s t . s p i d e r - e . c o m / n o n - w p / s p l o b _ f r e k k e r . p n g (If you take out all the spaces.) I'm wondering how you would layout the central segmented button? It's a large circle. The circle is split into four equal quadrants, and each quadrant is a separare button. I guess I could just do 5-different full size images (one for each possible button press, and one for no-button-preseeed) and then do some kind of hit test to see which area of the circle had been clicked. Or is there a way to draw a control which is non-linear in shape, like a quarter circle?
Posted Last updated
.
Post marked as solved
2 Replies
245 Views
Xcode 12 12A7209 crashes for me if I just try to open the developer documentation.
Posted Last updated
.
Post not yet marked as solved
2 Replies
284 Views
My latest app communicates, via TCP, with an embedded device. The embedded device is programmed in C and sends my Swift app data encapsulated in "messages" which are actually structures defined like this: { uint16_t sig; uint16_t len; // Total length of message, include header and playload; uint16_t type; uint32_t data; // 32 Bits of data. } MSG_t; In my Swit app they arrive via NWConnection, and are sent to my controller delegate as Data (That's the swift type called Data, not just the general term 'data') So me question for you harties is this: How can I unpack this 'Data' into something resembling my C struct - and acess it's members by name. In Pseudo code I'd like to do something like: if let myData = data { myStruct = <cast myData.bytes onto a struct > if myStruct.sig == CORRECT_MSG_SIG { // do soemthig with the message... } } So is this possible? Is it the wrong approach? Is there a better approach?
Posted Last updated
.
Post marked as solved
9 Replies
972 Views
I'm trying to send data using UDP using the following code, But I never get any 'newState' other than .preparing: Do I need to set an entitlement or something, or have I missed a point somewhere? (iOS 13, Xcode 11.7, SwiftUI) var connection: NWConnection? var hostUDP: NWEndpoint.Host = "239.255.250.78" var portUDP: NWEndpoint.Port = 4002 func start() { print("UDP Provider has started") self.connectToUDP(hostUDP, portUDP) } func connectToUDP(_ hostUDP: NWEndpoint.Host, _ portUDP: NWEndpoint.Port) {     let messageToUDP = "ANNOUNCE"     connection = NWConnection(host: hostUDP, port: portUDP, using: .udp)     connection?.stateUpdateHandler = { (newState) in       switch (newState) {         case .ready:           print("State: Ready\n")           self.sendUDP(messageToUDP)           self.receiveUDP()         case .setup:           print("State: Setup\n")         case .cancelled:           print("State: Cancelled\n")         case .preparing:           print("State: Preparing\n")         default:           print("ERROR! State not defined!\n")       }     }     connection?.start(queue: .global())   }   func sendUDP(_ content: String) {     let contentToSendUDP = content.data(using: String.Encoding.utf8)     connection?.send(content: contentToSendUDP, completion: NWConnection.SendCompletion.contentProcessed(({ (NWError) in       if (NWError == nil) {         print("Data was sent to UDP")       } else {         print("ERROR! Error when data (Type: Data) sending. NWError: \n \(NWError!)")       }     })))   }   func receiveUDP() {     connection?.receiveMessage { (data, context, isComplete, error) in       if (isComplete) {         print("Receive is complete")         if (data != nil) {           let backToString = String(decoding: data!, as: UTF8.self)           print("Received message: \(backToString)")         } else {           print("Data == nil")         }       }     }   }
Posted Last updated
.
Post not yet marked as solved
5 Replies
286 Views
I'm not really liking the new forums. I guess I don't really get how they are supposed to work. I can see how using 'tags' to post and find content removes the need for someone to keep creating and pruning topics, but it really seems like form-over-function to me. Here's my gripes.. I just want to browse through all the questions that are in my area of skill, but so far have no answers.. So in the past I'd have drilled through to something like "Developer / Objective-C" - now there seems to be no structure at all. No way to just browse around. There's so much whitespace! My mouse-miles are through the roof, there doesn't seem to be good use of screen real estate. You can't reply to a reply. Again this looses structure and makes following a thread really tricky. When I have a question I'll most likley post one thats been asked before because I don't know what tags the first person will have used. I can't easily see all my own questions, to see if I have any replies. I can't easily see what questions I have contributed to. Stack0verflow is far better laid out, has much more fucntionality, is easier to search, easier to see threads, ... just easier. But Apple's most valuable people aren't going to post replies there. You can't subscribe to a topic, or even a question, and get notifcations or emails when someone resonds. There's probably more, but I can't think straight right now...
Posted Last updated
.
Post not yet marked as solved
1 Replies
250 Views
I'm about to embark on quite a major new software release. It's a time-line based app (like iMovie or Final Cut Pro X) but it's not video editing. It's more like video arranging. (The app arranges video and audio clips for massive multi-screen displays, and then captures metadata from cameras and actors, while the videos are playing.). They don't play from the editor machine - it uploads them to client 'players' and simply controls and synchronises the playback of them. It will be exclusively for macOS (so no Windows or Linux) so I don't need anything which is cross-platform. There will be up to 100 'tracks' in the timeline, and on each track are multiple media clips (videos, animations, audio, etc) and each clip should show a thumbnail preview, and/or audio waveform. There will also be a preview pane in the UI, where any one selected media clip can be previewed, and an asset manager, and optional panes like data visualisers etc. So my questionn is, is SwiftUI a good choice for a complex userinterface, with a time-line style work area like this?
Posted Last updated
.
Post not yet marked as solved
10 Replies
1.9k Views
(Working on macOS and targetting macOS 10.11)I'm having trouble getting my head around decoding a given 'secret message' using a given Public Key.The 'secret message' is obtained from a device SDK call.The public key is given to me by the device manufacturer.The encyptedAPIToken is also gained from a SDK call to the device.The idea is to decode the secret using the public key. This yields a value which is then used to decode another secret using SHA-256, the final result is used as a token in HTTP GET and PUT headers to the device.The instructions from the device manufacturer are as shown in this picture.Since I can't embed images in this post, incase you can't see that, it says :1. Get the Public Key from the manufacturer.2. Decrpyt secret message with public key using RSA algorithm.3. Decrpyt encryptedAPIToken using SHA-256 algorithm using value gained in step 2.So that all seems pretty reasonable.Except I am having real trouble finding a way to decrpyt the secret message with the given public key.All the Objective-C/Swift examples I can find are for iOS which uses SecKeyRef - which is not availble on macOS.I found "Quin The Eskimo"'s CryptoCompatibility sample code from a few years back, but when I run it, like this:./CryptoCompatibility rsa-small-decrypt public.pem sigWhere "public.pem" is my public key, and sig is the secret in a text file, I get this error:CryptoCompatibility: error: NSOSStatusErrorDomain / -25256I am struggling to find examples of how to decrpyt a message using an RSA Public key for Objective-C or Swift, on macOS.
Posted Last updated
.
Post not yet marked as solved
1 Replies
304 Views
In an app I'm starting, I have a horizontal splitview (NSSPlitview) and in the top half of that I have another splitview (this time vertical) to make a 3-pane window. Two panes at the top, one across the bottom. A little bit like, say, FCP.Both NSSplitViews are using the thin-divider style.The issue is, if I resize the app window, or move any of the dividers, then the splitviews re-size correctly, but the original dividers stay on screen, in the original positions! Nothing I do after that will remove the original dividing lines.Here's a screenshot at app launch and here's a screenshot after resizing the app window.How do I remove these artefacts?
Posted Last updated
.
Post not yet marked as solved
2 Replies
967 Views
So, one of my apps is a companion app to a wireless streaming speaker.The speaker has a WPS button (Wifi Protected Setup) and the manufacturer (my client) wants me to add device discovery and connection into the app.It works like this :The user ensures that the iOS device is connected to the correct WiFi networkThe app promots the use for the correct WiFi passwordThe app prompts the user to press the WPS button on the speaker.The app then sends out whatever magic on the wifi network that allows the speaker to connect.I have seen this done already in other app (Muzo player for example).My question is: are there any libraries already for doing this, or is anyone aware of any sample code about that can help me?
Posted Last updated
.