Post

Replies

Boosts

Views

Activity

Thoughts while looking into upgrading from SCNetworkReachabilityGetFlags to NWPathMonitor
I have been using the SCNetworkReachabilityGetFlags for 10+ years to inform users that their request won't work. In my experience this works pretty well although i am aware of the limitations. Now, i am looking into the NWPathMonitor, and i have one situation that i'm trying to. get my head around - it's asynchronous. Specifically, i am wondering what to do when my geofences trigger and i want to check network connectivity - i want to tell the user why the operation i'll perform because of the trigger couldn't be done. SO. say i start a NWPathMonitor in didFinishLaunchingWithOptions. When the app is booted up because of a geofence trigger, might i not end up in a case where my didEnterRegion / didExitRegion gets called before the NWPathMonitor has gotten its first status? The advantage here with SCNetworkReachabilityGetFlags, as i understand it, would be that it's synchronous? If i want to upgrade to nwpathmonitor, i guess i have to do a method that creates a nwpathmonitor, uses a semaphore to wait for the first callback, then contunues? Thoughts appreciated
9
0
402
1d
UIKit flip animation bugged in 26.1
Hello. I have an 12 year old app that still has some objective-c code in it. I have a place where i have a flip animation between 2 view controllers that looks like this: [UIView transitionFromView:origView toView:newViewController.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromRight completion:nil]; It has looked like this since 2012 at least. In our production release, it works prior to 26.1, but in 26.1 and 26.2, the flip is off-center and looks weird. it's like both edges flip the same way. It's a little bit hard to explain. If seen at least 2 other app store apps that i have installed behave this way too, from 26.1 and onwards. Anyone else seen this? Is there anything that can be done about it? Thankful for thoughts.
14
3
559
3d
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
Updating Widget from App Intent called by Live Activity is inconsistent
(Also have a case ID, 9879068) We have an app that user use to check in/out from work for example. We have a button in-app do do this. Now I'm trying to add buttons to our widgets and our new live activity so that users don't have to open the app. It's crucial that the live activity and widgets always show the exact same state. Otherwise it'll look pretty bad if a user has both a live activity and a widget showin at the same time. However, we have noticed that sometimes, pressing the button in the live activity, running the app intent, will not always make the widget update (we call reloadAllTimelines()). The other way around, i.e. press the button on widget to update live activity always works. (they both call the same app intent) When running it in debug mode on a phone from Xcode, it always works, but when running it just on the phone it's unreliable. My first thought was, of course, that's related to the widget "budget", but according to the docs HERE, it should not be applied when interacting with a widget, calling an app intent. My question: HOW can I make my widget reliably refresh using an app intent invoked from a live activity?? I have a ready small project with simple buttons and trace labels that display this issue that I'm happy to supply to someone.
6
1
863
Nov ’24
Why is willPresentNotification called twice here?
Please find below a complete app example. It has a button, when you press it, a local notification is created. However, the UnNotificationCenter.delegate is called twice, and I can't understand why. I am trying to move my project from Objective-C to Swift, and my similar code there doesn't get called twice, so I'm confused. Can anybody shine a light on this? Pointers appreciated. App: @main struct NotifTestApp: App { init() { UNUserNotificationCenter.current().delegate = NotificationReceiveHandler.shared configureUserNotifications() } var body: some Scene { WindowGroup { ContentView() } } private func configureUserNotifications() { UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in if granted { print("Notification permission granted.") } else if let error = error { print("Error requesting notification permissions: \(error)") } } } } class NotificationReceiveHandler: NSObject, UNUserNotificationCenterDelegate { static let shared = NotificationReceiveHandler() //>> THIS IS CALLED TWICE WHEN I PRESS THE BUTTON func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { NSLog(">>> Will present notification!") completionHandler([.sound]) } } ///THE UI struct ContentView: View { var body: some View { VStack { Text("👾") .imageScale(.large) .foregroundStyle(.tint) Text("Notification test!") Text("When i press the button, will present is called twice!!").font(.footnote) .padding(10) Button("Create Notification") { createNotification( message: "This is a test notification", header: "Test Notification", category: "TEST_CATEGORY", playSound: true, dictionary: nil, imageName: nil) } .padding() .background(Color.blue) .foregroundColor(.white) .cornerRadius(8) } .padding() } } #Preview { ContentView() } private func createNotification(message: String, header: String, category: String, playSound: Bool = true, dictionary: NSDictionary? = nil, imageName: String? = nil) { let content = UNMutableNotificationContent() content.title = header content.body = message content.categoryIdentifier = category content.badge = NSNumber(value: 0) if let imageName = imageName, let imageURL = Bundle.main.url(forResource: imageName, withExtension: "png") { do { let attachment = try UNNotificationAttachment(identifier: "image", url: imageURL, options: nil) content.attachments = [attachment] } catch { print("Error creating notification attachment: \(error)") } } content.sound = playSound ? UNNotificationSound(named: UNNotificationSoundName("event.aiff")) : nil if let infoDict = dictionary { content.userInfo = infoDict as! [AnyHashable: Any] } let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil) UNUserNotificationCenter.current().add(request, withCompletionHandler: nil) }
9
3
2.6k
Nov ’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
Is there any way to start a live activity from a geofence trigger?
Hello, we have an app that has a case where the user can turn on a feature that starts a timer for a thing when they arrive at a specific location. Our app also has a live activity to show the timer. Naturally, we're trying to make our live activity to start counting when the geofence triggers, but we get ActivityAuthorizationError.visibility. If an activity is already running, it's possible to turn it off. So, our question is basically if there's any way to make the geofence trigger start our live activity? Thanks
3
0
792
Oct ’24
Can I fix this big difference between swiftui preview and actual watch widget layout?
Hi, working on customising my live activity Smart Stack layout for ios18. A thing that is very frustrating is that I consistently looks different for me in the Xcode preview and on the actual watch. See attached screenshots below. The sizes are different, and italic doesn't work on the watch, for example. It makes it time-consuming and unpredictable, so I was wondering if this is a known issue or if I'm doing something wrong, and also can I do anything? thanks edit: this is the layout: var body: some View { VStack(alignment: .center, spacing:4) { HStack(alignment: .center) { IconView(resource: "n-compact-w", bgColor: Color.checkedIn, padding: 2, paddingRight: 6, paddingBottom: 6) .frame(maxWidth: 25, maxHeight: 25).aspectRatio(1, contentMode: .fit) Text("Checked Out") .font(.title3).bold() } Text(status.loc) .font(.headline) .multilineTextAlignment(.center) Text(FormatUtils.getFormattedDateTime(status.time)).font(.subheadline) .multilineTextAlignment(.center).italic() } }
4
0
606
Oct ’24
How can I use an image for my live activity smartstack layout?
Hello, I am updating my live activity for the new ios18 Smart Stack functionality. I got it working through the WWDC session (Bring your live activities to Apple watch). I'm doing supplementalActivityFamilies([.small]) and then a custom layout in the .small ActivityFamily However, any images I try to use in the Smart Stack just show up as grey squares. (it works on the phone live activity) I suspect it's because my app images are not moved over to the watch? Because I don't have a watch app and such no watch target? If anyone can help me understand if there's anything I can do in order to have a custom image show up on the smart stack, I'd be very grateful.
3
0
651
Oct ’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
What is the reason for the CLLocationmanager.locationServicesEnabled() "invoked on main thread" warning?
I am looking into a piece of old code where the mentioned method is called. + (bool)isLocationServicesEnabled { return [CLLocationManager locationServicesEnabled]; } I'm getting the classic "This method can cause UI unresponsiveness if invoked on the main thread. Instead, consider waiting for the -locationManagerDidChangeAuthorization: callback and checking authorizationStatus first." I have 2 questions: What is that error about, really? The locationServicesEnabled() has nothing to do with authorisation, it's just about the "location services" settings global on-off switch? (the authorisation check is .authorizationStatus) I don't understand why that call is such a big issue? It's just a setting? Why would that be so costly? Thankful for pointers! Have a good one
5
0
1.2k
Sep ’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
How can I share code between app and widget that contains uiapplication?
OK, so I'm trying to share some utils classes for logging. The problem is a use-case where I want to create a debug notification. However, inside the app, I want to show a popup instead if the app is showing, but I can't share that code because it uses UIApplication.shared.ApplicationState. I've tried gating it off with all sorts of methods, @available etc. but I get compilation error "unavailable for application extensions" Example of me trying: static func doNotification(_ header: String, message: String) { //so I'm trying to gate off the code that only can be called in an extension , and in addition I have @available below if(isAppExtension()){ doNotificationFromExtension(header, message: message) }else{ doNotificationFromApp(header, message: message) } } @available(iOSApplicationExtension, unavailable) static func doNotificationFromApp(_ header: String, message: String) { let state = UIApplication.shared.applicationState if state != .active { //my dialog handler in-app popup }else{ NotifUtils.createLocalNotification(message, header: header, category: NOTIFICATION_CATEGORY_DEBUG, playSound: false) } } //here I know that I'm in an extension, so app isn't showing - always local notification static func doNotificationFromExtension(_ header: String, message: String) { NotifUtils.createLocalNotification(message, header: header, category: NOTIFICATION_CATEGORY_DEBUG, playSound: false) } static func isAppExtension() -> Bool { return Bundle.main.executablePath?.contains(".appex/") ?? false } Is there any way to share the code like this? The reason I want to do this is because I have various live activity code that I'd want to re-use, but this is a show.-stopper.
3
0
887
Aug ’24
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
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