Post

Replies

Boosts

Views

Activity

Would like feedback on handling multiple button presses while live activity intent Is processing
I am working on a live activity with a button that will do a network call when pressed on. I want to make sure that it can only be pressed once, and then ignored while the request is processed. This is what I did: Since it seems that a new intent object is created for each button press, I am using a static synchroniser like this: private var _isBusy: Bool = false private var _timestamp: Date? = nil private let queue: DispatchQueue private let resetInterval: TimeInterval init(resetInterval: TimeInterval = 60, queueLabel: String = "default.synchronizedBoolQueue") { self.resetInterval = resetInterval self.queue = DispatchQueue(label: queueLabel) } var isBusy: Bool { get { return queue.sync { return _isBusy } } set { queue.sync { _isBusy = newValue } } } func setIfNotBusy() -> Bool { return queue.sync { let now = Date() if let timestamp = _timestamp { if now.timeIntervalSince(timestamp) > resetInterval { // Reset if it was more than the specified interval ago _isBusy = false _timestamp = nil } } if !_isBusy { _isBusy = true _timestamp = now return true } return false } } func clearBusy() { queue.sync { _isBusy = false _timestamp = nil } } } Then, in my intent I have: private static let synchronizedBoolean = SynchronizedBoolean(queueLabel: "myIntent") ... func perform() async throws -> some IntentResult { NSLog("---LIVE perform() called") if(!UserEventIntent.synchronizedBoolean.setIfNotBusy()){ NSLog("---LIVE Was already in progress!") }else{ //doing intent logic here UserEventIntent.synchronizedBoolean.clearBusy() } } I am pretty new to Swift, so my hope is that someone more experienced than me could tell me if this a reasonable approach or if I'm missing anything? A big question - let's say I go into the perform() method, and while I'm in there, the user presses the button and the intent is called again. I get the "already in progress", but the method must still provide a result. Will that effect the intent already in progress? Thoughts much appreciated.
2
0
542
Aug ’24
Can't run Tomcat with local IP on Sequoia
Hi, just got upgraded this morning and now I can't use my local Tomcat install as server for my apps. I can access it in safari using localhost, but not using my computers IP. I start it from terminal. I looked everywhere in settings, and searched online of course, but have been unable to find an answer. Anyone knows how I can fit it? Input appreciated.
2
1
635
Sep ’24
Can I increase the reliability of my app intent updating my widgets?
We have widgets in our app. We're now working on a Live Activitiy with a button calling an app intent. This app intent needs to update our Widgets, and we're seeing semi-great results. When we're updating the widgets from within the app, it works great. Also from geofence triggers it usually works, so we're thinking it might have to do with the "widget update budget"? According to the docs: Cases in which WidgetKit doesn’t count reloads against your widget’s budget include when: The widget performs an app intent, such as when the user taps a button or toggles a switch. But we're not really seeing that. When I run our app from within Xcode, everything runs great all the time and the widget gets updated within milliseconds, but when running the TestFlight version is more spotty. To be clear: This is a button in a live activity, calling an app intent, and in turn, the app intent is calling reloadAllTimelines for our "regular" widgets. The live activity itself always gets updated properly. My question is basically, am I doing something wrong and can I do something to increase the consistency of the widget updating on time? Abbreviated example: final class UserEventIntent: NSObject, LiveActivityIntent { @MainActor func perform() async throws -> some IntentResult { do { let newStatus: (stat: Status, wasSame: Bool) = try await eventHelper.performEvent(status: status) WidgetCenter.shared.reloadAllTimelines() }catch { await WidgetCenterBridge.updateLiveActivityForInProgress(false) } return .result() }
2
0
448
Oct ’24
Need tips on adding AutoLayout UIView programmatically with Safe Area
I have a UIView that i create with a XIB. I then want to add it on top of a parent, take up the whole screen but use the safe area i have set up constraints for in the xib. I can add the view fine, but when i do, the safe area is ignored, and the view goes all the way to the top and bottom. The code i use (objective-c still sorry): (UIView *parent) MyViewController *newViewController = [[MyViewController alloc] initWithNibName:MY_VIEW_NIB_NAME bundle:nil]; [view setFrame:CGRectMake(0, 0, parent.bounds.size.width, parent.bounds.size.height)]; [parent addSubview:self.view]; In the Xib, i have the top and bottom constrained to SafeArea.top and bottom. It looks fine in the layout there. Any tips are appreciated.
1
0
943
Jan ’21
Is it possible to get a swiftUI timer-text to align .trailing?
Please consider simple example below. I am trying to put a timer in the upper right corner of a live activity. I am done, it works, but I'm trying to get the timer to look better. If I take a regular text, I can get it to align properly by adjusting the .frame(), , but for a text with a timer inside it, alignment is ignored from what I can see. Text("Hello").frame(width: 90, alignment: .trailing).border(.red) /*Text(timerInterval: timeRange, countsDown: false) .monospacedDigit().font(.subheadline).frame(width: 90, alignment: .trailing).border(.red)*/ } Is there any way to fix this? Right now, I have a fixed width so that HH:mm:ss will fit, but that doesn't look super great if it's just minutes and seconds for example, there's an empty block to the right
1
0
821
Jul ’24
Side-by-side comparison in source code changes view
I am trying to move over from AppCode/Intellij to Xcode. I am however having a hard time with the version control tools. I know that you can choose side-by-side when you activate "code review" and select single files. However, if you go into changes and view the list of files that have changed, i can only get inline-view to work. This is really frustrating to me, is there any way to get side-by-side also when you select a file from the changes list? Cheers
1
0
112
2w
Why can't i run my xcode project in simulator in 12+?
as the title suggests, i cant run my (objective c) project in xcode after upgrading to Xcode 12. It is a Cocoapods project. It works fine when i deploy to my phone, but in the simulator I get three different errors for some reason. It complains about "missing module map" for a separate project i include: module map file '...(path)/Build/Products/Debug-iphonesimulator/MyLibraryProject/MyLibraryProject.imagemap' not found 2. It complains about a precompiled header: <unknown>:0: error: failed to emit precompiled header '(path)/Build/Intermediates.noindex/PrecompiledHeaders/myProject-Bridging-Header-swift2UGSYUUFRK85M-clang18QKMU0TXX4JD.pch' for bridging header '(path)/iphone/myProject/myProject-Bridging-Header.h' 3. Finally it complains about Not finding a bundle for a library that i use: error: Resource "(path)/Products/Debug-iphonesimulator/FCAlertView/FCAlertView.bundle" not found. Run 'pod install' to update the copy resources script. Again, i can build and deploy to my phone, and submit to TestFlight/Appstore, but if i pick an emulator it's crash and burn. I am not very knowledgeable about xcode inner workings, so if anyone has any pointers, i'd be *most* grateful.
0
0
2.1k
Apr ’21
Interactive phone call push notification stopped working - only works in xcode
Hey, i have an app with a notification action that enables the user to make a phone call directly from the notification. I made this a good while ago, but we just noticed that it stopped working everywhere - except for when i install it via xcode. To make a long story short, what i do is that in didReceiveNotificationResponse, i get the phone number out from the payload and finally i call [application openURL:[NSURL URLWithString:[@"tel://+" stringByAppendingString:msisdn]] options:@{} completionHandler:nil]; This used to result in that the dialog pops up from the bottom with the phone number and a "call" button, but now it works when installed from xcode, but nothing happens when installed from testflight. I have made debug traces and it gets to the openurl-row with the correct phone number, but nothing seems to happen when i call it. Any idea what has changed? I made this several years ago and haven't touched the code. Pointers appreciated!
0
0
767
Mar ’22
Can't get SVG image to work in lockscreen widget
Hi, please consider the following widget view case .accessoryCircular: VStack{ Image(entry.icon).resizable().padding().border(.red) Text("IN") } EDIT, i also have tried this without success: Image(entry.icon).resizable().frame(height: gp.size.height * 0.30, alignment: .center) The image works if it's a PNG but now it's an SVG. I'm pretty much a SwiftUI noob, so i don't know how to get the image to work within the circular widget... or perhaps SVG isn't supported in lockscreen widgets? The error message i'm getting from the preview is The body of the Widget' entries contains an image of size(2094, 2010) which is beyond the maximum of (1418,8, 3067,2). That's a pretty strange error message to me, i thought the vstack would keep the image within the boundaries? also, I get the same message if i remove the text. Do i have to set the size explicitly?? In that case i have to hard-code it to some fixed widget size, right? I'd like to avoid that if possible. Grateful for pointers.
0
0
785
Oct ’22
Questions about Live Activities
Our app is a time reporting service with various functions around that. The user checks in at work, checks out when they go home. We thought it'd be useful to provide a live activity to show how long they have worked for. There is also a couple of other cool things we could do that users would love, but i couldn't find definitive answers to the questions below. 1. We have a geofence-based function that checks the user in when they for example arrive at work, and check them out when they go home, so that they don't have to open the app. However, this means that we will need to start and end the live activity from within a geofence trigger. Is this possible? 2. It seems that the maximum time for a live activity is 8 hours? Sometimes people work for longer... How would we solve this? i would be fine with 12 since it would solve most cases. Is it possible somehow to go beyond 8 hours up to 12? If not, is there a callback that "8 hours are up!" so that i could do a final update on the live activity from a counter to "you started working at 09:04" 3. I have seen that some live activities have buttons. It would be neat if the user can check out via a button on the live activity. However, since we take location and call our servers when checking out, we need to be able to use both the locationmanager and make a network call from the live activity. Is this possible? Thanks in advance, Cheers
0
0
986
May ’24
Why is my #available ignored by the compiler? (Xcode 15.4)
Hi, I have a workspace with a couple of modules, and now I'm making a Swift package. It's great. However, i have this SwiftUI View extension you can see at the end of this post. My Swift package needs to have the target set to IOS16, so i have added #available where I need, like I've done in the past. When i had this extension in my Widget extension target, it worked fine. However, i am now trying to move that into my new Swift package, with the Swift package declaration you can also find below. When moved, i get an error from the compiler: Type 'ContainerBackgroundPlacement' has no member 'widget' It seems that my #available is ignored? I'm at a loss as to why this happens, so if anyone has any ideas i'm all ears. Otherwise guess i'll have to move it back to the Widget extension target :( My extension code: extension View { func widgetBackground(_ color: Color) -> some View { if #available(iOSApplicationExtension 17.0, *), #available(iOS 17.0, *) { return containerBackground(color, for: .widget) } else { return background(color) } } .....more stuff } Swift Package (i renamed and cropped some stuff for simplicity): import PackageDescription let package = Package( name: "MyPackage", platforms: [ .iOS(.v16) ], products: [ .library( name: "MyPackage", targets: ["MyPackage"] ) ], targets: [ .target( name: "MyPackage" ), .testTarget( name: "MyPackageTests", dependencies: ["MyPackage"] ) ] )
0
0
598
Sep ’24