Post

Replies

Boosts

Views

Activity

SwiftUI dynamic positioning of a subview
Hi, I'm trying to figure out how to manually position a subview within a view using SwiftUI. For example, when the user taps the screen, I want to place a small icon on the screen at the position tapped. I know how to get the coordinates of the tapped location but I don't know how to either place a view there or move an existing view already being shown to that location. In a regular non-SwiftUI app I can set the frame, or set up constraints. I don't know what the best approach is in SwiftUI. Thanks.
1
0
448
Oct ’21
Bluetooth scanning in background without service ID?
Is there any way to scan for Bluetooth advertising messages while in the background if the device doesn't advertise any service IDs? I've been asked to build and app that does this. The device in question is an off-the-shelf medical alert button (my company doesn't make the device and can't alter its firmware). Upon examining it, I find that it does not advertise any service IDs nor does it offer any ability to connect, it works purely by sending advertising packets. I'm told that there are Android apps that can work with this device even while in the background. I checked the iOS bluetooth docs to see if any new scanning capabilities had been recently added, but could not find anything. Thanks, Frank
1
0
736
Dec ’21
Silent notification appears on home screen when app not open
I'm trying to send my app silent push notifications by setting the "content-available" flag to 1 in the notification payload. This works, but there is a problem: if my app is not running in the foreground, the notification is visible on the home screen. I don't want this: I just want the app to see it, without waking up the screen or alerting the user. If the app is open when the notification comes in, it works as expected; I receive the notification inside my app, and iOS does not display any alert or banner. I configured my app with the "Remote Notifications" background mode. What am I doing wrong?
1
0
739
Apr ’22
What is a BLE Scan Request?
Hi, I'm working with a BLE device manufacturer on a new device for which I'm tasked with developing the iOS app. The hardware developer told me: "In response to a Scan request (from a phone or other device) the BLE stack is configured to include a device identifier". The device identifier is something I need to see in the advertising packet before I connect to the device. I don't know what a "Scan request" is. Is this something I have to specifically ask for in my app? Is it something iOS does automatically? Thanks, Frank
0
0
961
Apr ’22
iPhone app in Portrait only?
I can't get my latest iPhone app to run in portrait mode only. In Xcode I've checked only the box that says "Portrait" under Device Orientation, and I've also examined the Info.plist file to ensure that there aren't any hidden settings for other orientations. I've also tried checking or un-checking iPad, and checking "Requires Full Screen" when that option appears. No matter what I do, when I run the app on my phone and rotate the screen, the interface rotates. What am I doing wrong?
1
0
961
Jul ’22
Weird Swift bug with Equatable
I've got an iOS project that I've been working on for some months. Just recently, I started seeing a compiler error to the effect that "Referencing instance requires that X conforms to Equatable". It shows up in places where you'd expect something to be Equatable, such as the argument to firstIndexOf: on an array. The class in question is written in Swift, but descents from an Objective-C base class. I know there are some issues with how Equatable interacts with Obj-C but I think I've done it right. The base class extends NSObject, and the subclass implements both the isEqual function and the static == function. (I don't think the latter is necessary but I included it just in case). I've tried explicitly including "Equatable" in the definition of the subclass but the compiler rejects this as "Redundant conformance to protocol". I'm not exactly sure how that works since NSObject doesn't extend Equatable but I guess Swift considers them equivalent. Here's where things get super weird though. Xcode still builds and runs the project despite the compiler error, and the code runs, and it works. I even put a breakpoint in the isEqual function to make sure it was getting called. Also, when I clean and rebuild the project, the compiler error often disappears for some time, reappearing hours or days later. So I think this must be some kind of bug in Xcode or Swift itself. What do you think? Frank
1
0
583
Jul ’22
Need help with autolayout solution
Views A and B are equal in width (set up via a constraint). The actual width will vary at runtime. What I want to do is arrange view A such that it is horizontally centered on B but offset to the left by 1/10th of the total width. In other words, if views A and B were 100 units in length, I'd want A to be positioned 10 units to the left of B. If the width were 150 units then the A position would be 15 to the left, etc. I thought I could do this with either a leading constraint or a centerX constraint using a multiplier of 0.9, but it isn't working out the way I want. What's the best solution?
1
0
669
Jul ’22
replacingOccurrences(of:,with:) always returns new string?
Do string functions such as "replacingOccurrences" and "trimmingCharacters" always return a new string, even if the old string did not need to be modified? In other words -- if I'm doing a large number of "replacingOccurrences" in my app but only a small number of the strings actually contain the sequence I want to replace, should I check to see if the sequence exists before calling replacingOccurrences, in order to avoid an unnecessary string allocation? I would guess that Swift would return the same string if it didn't require any modifications, but the documentation just says "Returns a new string". Thanks, Frank
1
0
703
Sep ’22
How are referral codes handled today?
Hi, My customer wants to do the thing where an app store URL is advertised which contains a referral code. When a user follows the link, it should take them to the app store to install the app, and then when the app is installed, it should be able to get access to the referral code in the original URL. I know such a thing was possible at one time because I remember talking to some of my colleagues about it, but I have never done it myself and whatever my coworkers did 8 years ago in Objective-C probably doesn't work anymore. Can someone let me know how to do this, or at least, let me know what the correct name for this procedure is so I can look it up? Thanks.
2
0
6.7k
Dec ’22