Hi there!
I am tying to add and select a map pin using view long press when the gesture is begin.
However after adding and selecting the pin it got deselected immediately, my assumption that it's conflicting when the original map gesture and it's deselecting the pin on the map (like if a pin was selected and you click anywhere on the map to deselect it).
Note that if I increase minimumPressDuration for the UILongPressGestureRecognizer it works fine, but I want the value at 0.5 so the pin is quickly added.
here is the full code:
import SwiftUI
import MapKit
struct ContentView: View {
@State var selection: CustomMapSelection?
@State private var longPressPosition: CGPoint = .zero
@State private var pinCoordinate: CLLocationCoordinate2D?
var body: some View {
MapReader { proxy in
Map(selection: $selection) {
if let pinCoordinate {
Marker("Custom Location", coordinate: pinCoordinate)
.tag(CustomMapSelection(coordinate: pinCoordinate))
}
}
.gesture(LongPressGestureRecognizer(position: $longPressPosition))
.onChange(of: longPressPosition) {
if let coordinate = proxy.convert(longPressPosition, from: .global) {
pinCoordinate = coordinate
selection = CustomMapSelection(coordinate: coordinate)
}
}
}
}
}
struct CustomMapSelection: Hashable {
let latitude: Double
let longitude: Double
init(coordinate: CLLocationCoordinate2D) {
latitude = coordinate.latitude
longitude = coordinate.longitude
}
}
struct LongPressGestureRecognizer: UIGestureRecognizerRepresentable {
@Binding var position: CGPoint
func makeCoordinator(converter: CoordinateSpaceConverter) -> Coordinator {
Coordinator()
}
func makeUIGestureRecognizer(context: Context) -> UILongPressGestureRecognizer {
let recognizer = UILongPressGestureRecognizer()
recognizer.delegate = context.coordinator
// if you make the minimumPressDuration above 2, it works fine and the selection doesn't cancel
recognizer.minimumPressDuration = 0.5
return recognizer
}
func handleUIGestureRecognizerAction(_ recognizer: UILongPressGestureRecognizer, context: Context) {
if recognizer.state == .began {
let position = recognizer.location(in: recognizer.view)
self.position = position
}
}
class Coordinator: NSObject, UIGestureRecognizerDelegate {
func gestureRecognizer(
_ gestureRecognizer: UIGestureRecognizer,
shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer
) -> Bool {
return true
}
}
}
#Preview {
ContentView()
}
Post
Replies
Boosts
Views
Activity
Hi, I am getting and invalidJWTResponse when using WeatherKit Swift API, I have setup everything correctly including enabling WeatherKit in both Capabilities and App Services, Added WeatherKit" to Xcode Capabilities, and waited for more than one day!
But still it's not working!
invalidJWTResponse(Optional(<NSHTTPURLResponse: 0x6000008d8300> { URL: https://weather-data.apple.com/v2/token } { Status Code: 401, Headers {
Connection = (
close
);
"Content-Length" = (
0
);
Date = (
"Thu, 09 Jun 2022 18:24:24 GMT"
);
Server = (
"AppleHttpServer/5712591c84160e0cbbf19c8f434c32ab02f2a7f4"
);
"Strict-Transport-Security" = (
"max-age=31536000"
);
"X-Apple-Origin" = (
"01ca7adc-14e8-31f5-9654-4375b40868e2"
);
"X-B3-TraceId" = (
795fbfea426330d9
);
"X-Cache" = (
"TCP_MISS from a88-221-161-85.deploy.akamaitechnologies.com (AkamaiGHost/10.8.2-41841244) (-)"
);
"X-REQUEST-ID" = (
"3e6d21c8-ffa0-4c56-aa91-8466619a4993"
);
} }))
After the release of iOS 15.4, I am receiving so many crash reports for CarPlay, and the percentage increased to +140%!
Here is one of the crash logs:
Crash Log
And here is a screenshot from Xcode Organizer, which shows too many wired crashes:
I am trying to use SFSymbols with the newly introduced CPNowPlayingImageButton, but I am always getting the image as a black image.
let shuffleButton = CPNowPlayingImageButton(image: UIImage(systemName: "shuffle")!) { button in
button.isSelected = PlayerManager.shared.playMode == .random
PlayerManager.shared.playMode = .random
}
I tried changing the color of the SFSymbol image but it didn't work at all, it always shows a black image regardless of anything else!
I am trying to localize my widgets depending on the app language, but when I try to get supported languages in my app from the widget extension using:
Bundle.main.preferredLocalizations
// returns "en" only
But if I used the same code in the main app, it returns all languages supported in my app.
Any solution for that?