Calling DNSServiceNATPortMappingCreate returns kDNSServiceErr_NoError like expected but the port mapping actually fails right away in the callback.
I'm calling this in a daemon via XPC. Are there new restrictions or permissions required?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
This code works fine on macOS 11:
var body: some View {
VStack {
ActionControl()
.padding()
.onDrag { () -> NSItemProvider in
let value = Action(string: "hello, world").string
let p = ActionProfile(value: value)
return NSItemProvider(item: p, typeIdentifier: ActionProfile.pasteboardType)
}
MyTextView()
.padding()
}
}
class ActionProfile: NSObject, NSCoding, NSSecureCoding {
static var supportsSecureCoding: Bool = true
static var pasteboardType = "com.my.app.action.profile"
@objc var rawValue: String
func encode(with aCoder: NSCoder) {
aCoder.encode(rawValue, forKey: "value")
}
required init(value: String) {
self.rawValue = value
}
required init?(coder aDecoder: NSCoder) {
self.rawValue = aDecoder.decodeObject(of: NSString.self, forKey: "value")! as String
}
required init?(pasteboardPropertyList propertyList: Any, ofType type: NSPasteboard.PasteboardType) {
return nil
}
}
extension ActionProfile: NSPasteboardWriting, NSPasteboardReading {
static var nsPasteboardType: NSPasteboard.PasteboardType = .init(pasteboardType)
static func readingOptions(forType type: NSPasteboard.PasteboardType, pasteboard: NSPasteboard) -> NSPasteboard.ReadingOptions {
return .asKeyedArchive
}
func writableTypes(for pasteboard: NSPasteboard) -> [NSPasteboard.PasteboardType] {
return [ActionProfile.nsPasteboardType]
}
func pasteboardPropertyList(forType type: NSPasteboard.PasteboardType) -> Any? {
if type == ActionProfile.nsPasteboardType {
return try! NSKeyedArchiver.archivedData(withRootObject: self, requiringSecureCoding: false)
}
return nil
}
static func readableTypes(for pasteboard: NSPasteboard) -> [NSPasteboard.PasteboardType] {
return [ActionProfile.nsPasteboardType]
}
}
extension MyTextViewControl {
override internal var writablePasteboardTypes: [NSPasteboard.PasteboardType] {
return [ActionProfile.nsPasteboardType] + super.writablePasteboardTypes
}
override func prepareForDragOperation(_ sender: NSDraggingInfo) -> Bool {
return true
}
override func draggingUpdated(_ sender: NSDraggingInfo) -> NSDragOperation {
let location = self.characterIndexForInsertion(at: self.convert(sender.draggingLocation, from: nil))
self.setSelectedRange(NSRange(location: location, length: 0))
return sender.draggingSource is MyTextViewControl ? .move : .copy
}
override func performDragOperation(_ sender: NSDraggingInfo) -> Bool {
let pboard = sender.draggingPasteboard
if pboard.availableType(from: [ActionProfile.nsPasteboardType]) == ActionProfile.nsPasteboardType {
if let profiles = pboard.readObjects(forClasses: [ActionProfile.self], options: nil) as? [ActionProfile], !profiles.isEmpty {
let alert = NSAlert()
alert.messageText = "WORKS"
alert.runModal()
return true
}
else {
let alert = NSAlert()
alert.messageText = "FAILED"
alert.runModal()
return super.performDragOperation(sender)
}
}
return super.performDragOperation(sender)
}
}
On macOS 12 beta, when calling pboard.readObjects(...) I get this error when trying to drag the item into a NSTextView:
Failed to initialize keyed unarchiver for pasteboard data: Error Domain=NSCocoaErrorDomain Code=4864 "*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: data is empty; did you forget to send -finishEncoding to the NSKeyedArchiver?" UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: data is empty; did you forget to send -finishEncoding to the NSKeyedArchiver?}
I've noticed that encode(with aCoder: NSCoder) isn't called at all on macOS 12 but is on macOS 11.
Are there any changes in macOS 12 regarding NSCoding or NSSecureCoding or is this just a bug?
Am I wrong or is it not possible to share Core Data+CloudKit with a keyboard extension?
It works if I set an app group but then I lose the CloudKit sync feature, which is not acceptable for me.
Is there some other way to share the data while keeping sync?
In my app, I'd like to be able to share a .csv file via ShareLink and Transferable. I watched the "Meet Transferable" WWDC22 video and it should be possible as the presenter demonstrated that use case.
However, when I try this on my end, I am able to share the content but somehow it is treated by iOS as plaintext and when sharing by email or messages, it will just add the text content to the body.
If I try to share via AirDrop, it creates a random filename with the .txt extension even though I specify .commaSeparatedText.
The only way this somewhat works is when saving to files. It will save as a .csv file but the filename is set to "comma-separated values".
Here's some code:
struct MyArchive {
enum ValidationError: Error {
case invalid
}
var filename: String {
return "myarchive.csv"
}
init(csvData: Data) throws {
//...
}
func convertToCSV() throws -> Data {
let test = "Name,Email\nPete,pete@example.com"
if let data = test.data(using: .utf8) {
return data
}
else {
throw ValidationError.invalid
}
}
}
extension MyArchive: Transferable {
static var transferRepresentation: some TransferRepresentation {
DataRepresentation(contentType: .commaSeparatedText) { archive in
try archive.convertToCSV()
} importing: { data in
try MyArchive(csvData: data)
}
}
}
And in my View:
struct View: View {
var body: some View {
//...
let csv = MyArchive()
ShareLink(
item: csv,
preview: SharePreview(
csv.filename,
image: Image(systemName: "doc.plaintext")
)
)
}
}
I'm at the point that I wonder if I'm doing something wrong or this just doesn't work in iOS 16 beta 1.
Any hints?
Thanks!
I'm able to retrieve the URL for iCloud Drive but what I want to do is store my app documents in the "On My iPad" / MyApp.
Using FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) just returns the document folder for the app container.
How can I access the public folder?
Thanks!
As of now, it seems impossible to set focus on a text field that is embedded in an alert on macOS.
struct ContentView: View {
@FocusState private var focusedField: FocusField?
@State private var showingAlert = false
@State private var name = ""
enum FocusField {
case folderName
}
var body: some View {
VStack {
Button {
// focusedField = .folderName // Not working either
showingAlert.toggle()
} label: {
Text("Show alert")
}
.alert("Alert", isPresented: $showingAlert, actions: {
TextField("Name", text: $name)
.font(.body)
.autocorrectionDisabled()
.focused($focusedField, equals: .folderName)
Button("Cancel", role: .cancel, action: {})
})
#if os(macOS)
.defaultFocus($focusedField, .folderName)
#endif
}
.padding()
}
}
When running this code on iOS, the text field does get focus automatically. Is it me that is doing something wrong or it's just a SwiftUI shortcoming on macOS?
Why won't a button using a Label show in the keyboard shortcuts list (holding ⌘ key)?
struct ContentView: View {
var body: some View {
NavigationSplitView {
SidebarView()
} detail: {
Text("Hello, world")
}
}
}
struct SidebarView: View {
let items = [1, 2, 3, 4, 5, 6]
var body: some View {
List(items, id:\.self) { item in
Text("\(item)")
}
.toolbar {
Button {
// Do something
} label: {
Label("New", systemImage: "plus")
}
.keyboardShortcut("n") // Will NOT show in shortcuts list
Button("Play") {
// Do something
}
.keyboardShortcut("p") // Will show in shortcuts list
}
}
}
Am I doing something wrong or is this just yet another SwiftUI shortcoming?
Is there no way to hide the pointer with SwiftUI? If so, how?
Somehow the Swift compiler is unable to this code:
@Observable class ServiceBrowser: NSObject {
typealias ResolveServiceCompletionBlock = (Bool, Error?) -> Void
fileprivate var resolveServiceCompletionHandler: ResolveServiceCompletionBlock? = nil
}
Here's the crash:
4 . While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/Users/luc/Work/Repositories/app-shared/App/Shared/Connectivity/ServiceBrowser.swift")
5 . While silgen init accessor SIL function "@$s7App14ServiceBrowserC07resolveB17CompletionHandler33_5B15C352D9CC926D1F8A0ECAC5970199LLySb_s5Error_pSgtcSgvi".
for init for resolveServiceCompletionHandler (at /Users/luc/Work/Repositories/ap-shared/App/Shared/Connectivity/ServiceBrowser.swift:86:21)
6 . While emitting reabstraction thunk in SIL function "@$sSbs5Error_pSgIegyg_ytIegd_TR".
DNSServiceNATPortMappingCreate returns external port 0 since macOS 13 b3 build 23A5286i.
This was the case in macOS 12 as well (see FB9137313 and FB9139688).
Hopefully this won't take months after macOS is released before it is fixed like last time.
Latest radar: FB12579235
Also, see https://developer.apple.com/forums/thread/681836
How come keyboard shortcuts associated to toolbar items do not show up when you hold down the command key?
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationStack {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
Button {
} label: {
Text("Tap Me!")
}
.keyboardShortcut("o", modifiers: .command)
}
.padding()
.toolbar {
ToolbarItem {
Button {
} label: {
Image(systemName: "bolt")
}
.keyboardShortcut("k", modifiers: .command)
}
}
}
}
}
See screenshot. The shortcut for "Tap Me!" is being shown but not the one for the toolbar item. Am I doing something wrong or this is just not supported yet in SwiftUI? If that's the case, that seems to be a significant omission.
Like title says. Why make users jump through hoops on macOS to redeem a code while it's trivial on iOS?
At least make the button open the Mac App Store app to the redeem sheet!
FB13202274
I've spent 3 days moving localization from my older project to my new project and converted to Strings Catalog.
When I tried to export, I got the Unable to build project for localization string extraction error.
Read about that and the workaround seems to be to set Localisation Export Supported to NO, which I did.
I worked once and now it refuses to export and complains about missing targets, which I had to remove from the export process as recommended. WTH?
Or, at some point it complained about a missing Swift Package.
wwdc2023-10155
Trying to debug StoreKit on device using a sandboxed user. When I want to show manageSubscriptionsSheet, the screen flashes but nothing shows.
This is visible in the console:
SKEngagementRemoteViewTask: Presenting system engagement request. Request: {length = 5347, bytes = 0x62706c69 73743030 d4010203 04050607 ... 00000000 000012d7 }
Present engagement request: {length = 5347, bytes = 0x62706c69 73743030 d4010203 04050607 ... 00000000 000012d7 }, clientBundleID: com.acme.myapp
Finished presenting engagement request with view service
There isn't much information in the documentation so I'm not sure if it's me not doing things correctly or a bug in iOS 17.2?
Calling StoreKit.Transaction.currentEntitlements today just doesn't return. It just sits there.
for await result in StoreKit.Transaction.currentEntitlements {
switch result {
case .verified(let transaction):
currentTransaction = transaction
case .unverified(let transaction, let error):
currentTransaction = transaction
}
}
The for loop never starts.
This is using a Sandboxed user that made a renewal subscription purchase. Everything was working fine yesterday. Nothing on my end has changed since then.
Is something wrong with StoreKit?