Post

Replies

Boosts

Views

Activity

Background Service To Fetch Data
Hi all. This is more of a discussion thread than a question about getting some code answers. I am reading about background tasks and the Apple documentation example is not even complete and unusable. Just bits and pieces of code so a newbie like me doesnt find it helpful. What I am trying to do is run a background task even when the app is closed at 3 hour intervals. I have not seen any solution to this. is this possible? I figured trying to also look if it is possible to listen to when the user's internet connection is on or off because once it will be one, the service will run. if the internet is turned off, it disables the service (is this possible?) I used this url as guide https://developer.apple.com/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_background/using_background_tasks_to_update_your_app#3193599 Note: I dont even know what RefreshAppContentsOperation is. At least they should have included the source for this. Or even if it's part of the sdk, at least include the import for this.
0
0
662
Feb ’23
BGTaskScheduler.shared.register() does not get called
Hi all. Any clue why BGTaskScheduler.shared.register() does not get called? The print does not show anything to console. I already registered them in Permitted Background task scheduler identifiers and added 2 items for package.Task.updateAppRefresh package.Task.updateAppProcessing I re-read the tutorial and I cannot figure out what else i am lacking? Thoughts?
2
0
1.3k
Mar ’23
Build Input File Cannot Be Found .app
This one is about the .app not found. I am not sure why. And i have not seen a post about a .app not being found. Build input file cannot be found: '.../DerivedData/...../Build/Products/Debug-iphonesimulator/......app/.....'. Did you forget to declare this file as an output of a script phase or custom build rule which produces it? Thoughts what could be wrong?
1
0
951
Mar ’23
touch events do not work in ipad air and pro
what happened? i never noticed it until i decided to use ipad air and pro as option in chrome dev console mobile view as well as ios simulator. it works ok in the ipad mini. touch events do not get triggered. instead, the scroll seems to overlap these. EDIT: Solved. please see comment below. While it works ok in ipad pro devices now, I still wish this could work out in chrome's dev console ipad pro view. the behavior is different with click events. instead of mouse down, it starts with mouse move. what gives? this only happens in ipad air and pro view in the device toolbar in dev console.
1
0
994
Jan ’24
How to disable cache in URLSession.shared.data in SwiftUI
All I have come across are NSURLSession. Is this possible for URLSession? How? I noticed my requests show up instantly so I figured these reponses are cached instead of fetching new ones. Caching should not be the default. Weird why it was set this way. Thoughts? This is my code. It is basic let url = URL(string: urlLink)! let (data, _) = try await URLSession.shared.data(from: url) print(String(decoding: data, as: UTF8.self))
1
0
3.4k
Oct ’22
Callouts in Map Marker
Hi, does anyone have some short code to display a marker with callout? There simply is no updated documentation of it. They are either using old names or I just have not found any tutorial of it. I only found about MapMarker, but then it only shows a pin. on the map and no callout is possible. This is what I have  Map(coordinateRegion: $mapRegion, showsUserLocation: true, annotationItems: markers) { marker in marker.location } Where marker.location is MarkerMap. So it displays a pin correctly, but how to add a callout and link to it? There are so many different names that start with MK. I am not sure if those are the latest. I figure MapAnnotation, MapMarker to name a few are the latest ones.
1
0
1.6k
Oct ’22
What Happened to NSAttributedString in Swift 5? Bold Doesnt work?
The various posts showing NSAttributedString rendering html tags has become mute because the bold tag does not work anymore. Anyone know why? Or what the workaround is? I am using this as the extension in string (found this in stackoverflow)    var htmlAttributedString: NSAttributedString? {     do {       return try NSAttributedString(data: Data(utf8), options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html], documentAttributes: nil)     } catch {       return nil     }   }       var htmlString: String {     return htmlAttributedString?.string ?? ""   } Bold just doesnt work. I do not see anything wrong with the code itself. It looks right. But it just does not render bold. I read about adding style tag in the string with the default apple system font in it hardcoded, tried that but didnt work out still.
1
0
758
Oct ’22
Why Does Method Force Me To Add Mutating
Regardless if I use a protocol or not that contains this method, e.g. I have this var test: String? func setupData() -> Void { test = "New value" } Why does it say Cannot assign to property: 'self' is immutable" So if i add mutable to setupData() which becomes "mutating func setupData() { ... }", then i get another error message Cannot use mutating member on immutable value: 'self' is immutable I call setupData in onAppear() instead of init() for now. Putting it in init forces me to initialize the variables (sucks) I am lost on this one. Advise? This is used inside a Struct View. not a class.
1
0
1.7k
Nov ’22
How To Zoom In Using northeast, southwest and center coordinate In Swiftui Map
I have the coordinate for northeast, southwest and center coordinates for a country Philippines but it does not zoom in there. This is the code I am using in OnAppear in the map view @State private var region = MKCoordinateRegion() var body: some View {     Map(coordinateRegion: $region)     .edgesIgnoringSafeArea(.all)     .onAppear() {       region = MapTool.getPARCoordinateRegion()     }   } static func getPARCoordinateRegion() -> MKCoordinateRegion {     let ph = getPHCountryPlaceMark()     let southWestPoint = MKMapPoint(x: ph.southWestLongitude, y: ph.southWestLatitude)     let northEastPoint = MKMapPoint(x: ph.northEastLongitude, y: ph.northEastLatitude)     let northWestPoint = MKMapPoint(x: southWestPoint.x, y: northEastPoint.y)     let mapRectWidth = northEastPoint.x - northWestPoint.x     let mapRectHeight = northWestPoint.y - southWestPoint.y     return MKCoordinateRegion(MKMapRect(x: southWestPoint.x, y: southWestPoint.y, width: mapRectWidth, height: mapRectHeight))   } static func getPHCountryPlaceMark() -> CountryPlaceMark {     let countryPlaceMark = CountryPlaceMark()     countryPlaceMark.longName = "Philippines"     countryPlaceMark.shortName = "PH"     countryPlaceMark.centerLatitude = 12.879721     countryPlaceMark.centerLongitude = 121.774017     countryPlaceMark.southWestLatitude = 4.613444     countryPlaceMark.southWestLongitude = 116.931557     countryPlaceMark.northEastLatitude = 19.574024     countryPlaceMark.northEastLongitude = 126.604384     return countryPlaceMark   } But instead zooms here. Thoughts?
1
0
627
Oct ’22
How To Declare A Variable of Type Function and Pass Function To it?
Is this possible? I have a class/struct that will store a function that will be used as an action to the button. e.g. struct Test { var action: (() -> Void)? } This works tempfunc() -> Void { print("clicked it") } let test = Test() test.action = tempfunc Button("click me", action: test.action) What I want to do is something like this. test.action = () -> Void { print("clicked") } Is this possible? If i try that code, error shows up saying "Cannot assign value of type '()' to type '() -> Void'"
1
0
546
Oct ’22
How To Create Heatmap From Array CLCoordinate2D In A SwiftUI Map
Hi, is there a heatmap class that can be used in a SwiftUI Map? I do not want to use MKMapView and I have seen libraries that are not Swifty and does not make use of the new Map() Tips are welcome on how to go about this? Or if anyone has a sample code? I basically have an array of CLCoordinate2D and i wish to use that to generate a heatmap in the map. No Google Maps please. I decidede not to use this since they do not have a SwiftUI version for it.
5
0
1.9k
Oct ’22
Region In MKMapView Not Updating In onAppear
Hi. This is my MapView code import SwiftUI import MapKit struct MapView: UIViewRepresentable {   var region: MKCoordinateRegion   var polylineCoordinates: [CLLocationCoordinate2D]?   func makeUIView(context: Context) -> MKMapView {     let mapView = MKMapView()     mapView.delegate = context.coordinator     mapView.region = region          if let polylines = polylineCoordinates {       let polyline = MKPolyline(coordinates: polylines, count: polylines.count)       mapView.addOverlay(polyline)     }           return mapView   }   func updateUIView(_ view: MKMapView, context: Context) {        }   func makeCoordinator() -> Coordinator {     Coordinator(self)   } } class Coordinator: NSObject, MKMapViewDelegate {   var parent: MapView   init(_ parent: MapView) {    self.parent = parent   }       func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {     if overlay is MKPolyline {       let routePolyline = overlay as! MKPolyline       let renderer = MKPolylineRenderer(polyline: routePolyline)       renderer.strokeColor = UIColor.white       renderer.lineWidth = 2       return renderer     }     return MKOverlayRenderer()   } } If i do this var body: some View {     MapView(region: [array of CLLocationCoordinage2D])     .edgesIgnoringSafeArea(.all) } it works since the value of the region property is set in the constructor. However, what i want is to set the region property in the onAppear closure. What is lacking here since it does not work. I wish to do something like this var body: some View {     MapView(region: region)     .edgesIgnoringSafeArea(.all) .onAppear { region = [array of CLLocationCoordinage2D] } } I want to apply the same thing to polylineCoordinates property but for now, if I can make it work with region, I am sure the same thing can be applied to polylineCoordinates property. Thoughts?
1
1
659
Oct ’22
How to Shorten if let variable = optionalVariable { }
Hi, beginner here. So I have read how 1 way to use an optional without having to be forced to unwrap it with ! is this ... if let var1 = optionalVar1 { } This is not a prob. But what if i have too many optionals? I do not want to have nested if let blocks. Is there a shorter way not to do too many ifs that without having to unwrap it with ! ? e.g. if let var1 = optionalVar1 { if let var2 = optionalVar2 { if let var3 = optionalVar3 { } } }
1
0
433
Oct ’22
Most Optimal Way To Fetch Data In A SwiftUI View Once?
I wish to ask for suggestions how to go about how to fetch data once it is successful in a swift ui view. Where is it best to put it? What annotation is best suited for this? I have a map view and it fetches data first before showing marker annotations. I put it in onAppear. This may work if it is just 1 view. But if this view is used inside a TabView, then once the tab is selected, the onAppear block will be executed and will be fetched again. What is the best way to go about this by fetching the data only once? Thoughts? var body: some View {     TabView {       MapView(cameraUpdate: ...)       .onAppear() {                   // fetch data here.       }       .onDisappear() {                 }       .tabItem {         Label("tab2, systemImage: "list.dash")       }             MapView(cameraUpdate: ...)       .onAppear() {                          }       .onDisappear() {                 }       .tabItem {         Label("tab2, systemImage: "list.dash")       }     }     .onAppear() {             }   }
1
0
1.7k
Oct ’22