It's so bad seeing this light mode...
Can I ask Apple to give me an access to their frontend, so I can contribute to their repo with a dark mode feature?
Not asking Apple to make the dark theme, but rather asking them let me do it.
Post
Replies
Boosts
Views
Activity
Consider this simple miniature of my iOS Share Extension:
import SwiftUI
import Photos
class ShareViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
if let itemProviders = (extensionContext?.inputItems.first as? NSExtensionItem)?.attachments {
let hostingView = UIHostingController(rootView: ShareView(extensionContext: extensionContext, itemProviders: itemProviders))
hostingView.view.frame = view.frame
view.addSubview(hostingView.view)
}
}
}
struct ShareView: View {
var extensionContext: NSExtensionContext?
var itemProviders: [NSItemProvider]
var body: some View {
VStack{}
.task{
await extractItems()
}
}
func extractItems() async {
guard let itemProvider = itemProviders.first else { return }
guard itemProvider.hasItemConformingToTypeIdentifier(UTType.url.identifier) else { return }
do {
guard let url = try await itemProvider.loadItem(forTypeIdentifier: UTType.url.identifier) as? URL else { return }
try await downloadAndSaveMedia(reelURL: url.absoluteString)
extensionContext?.completeRequest(returningItems: [])
}
catch {}
}
}
On the line 34
guard let url = try await itemProvider.loadItem
...
I get these warnings:
Passing argument of non-sendable type '[AnyHashable : Any]?' outside of main actor-isolated context may introduce data races; this is an error in the Swift 6 language mode
1.1. Generic enum 'Optional' does not conform to the 'Sendable' protocol (Swift.Optional)
Passing argument of non-sendable type 'NSItemProvider' outside of main actor-isolated context may introduce data races; this is an error in the Swift 6 language mode
2.2. Class 'NSItemProvider' does not conform to the 'Sendable' protocol (Foundation.NSItemProvider)
How to fix them in Xcode 16?
Please provide a solution which works, and not the one which might (meaning you run the same code in Xcode, add your solution and see no warnings).
I tried
Decorating everything with @MainActors
Using @MainActor in the .task
@preconcurrency import
Decorating everything with @preconcurrency
Playing around with nonisolated
I can't upload my macOS app to app store connect.
Each time i try to upload, i see this message:
Provisioning profile failed qualification
Profile doesn't support App Groups.
An empty app without an app group uploads fine, but if i add an app group to it, it does not upload.
Hi. I'm a developer of Tab Finder (https://apps.apple.com/us/app/tab-finder/id6741719894)
My problem is that every time i switch from my first window to a second window, the tabs in the validateToolbarItem() are INcorrect on a first call, but when I switch back from the second window to my main window, the tabs are CORRECT even on a first call.
To demonstrate it, i recorded a video: https://youtu.be/RwskzrSJ8u0
To run the same sample extension from the video, you can get the code from this GitHub repo: https://github.com/kopyl/test-tabs-change
Its only purpose is to log URLs of an active page of all tabs.
The SafariExtensionHandler's code of the sample app is very simple:
import SafariServices
func printOpenTabsHost(in window: SFSafariWindow) async {
let tabs = await window.allTabs()
log("Logging tabs for a new window: \(window.hashValue)")
for tab in tabs {
let page = await tab.activePage()
let properties = await page?.properties()
let url = properties?.url
log(url?.absoluteString ?? "No URL")
}
}
class SafariExtensionViewController: SFSafariExtensionViewController {
static let shared = SafariExtensionViewController()
}
class SafariExtensionHandler: SFSafariExtensionHandler {
override func validateToolbarItem(in window: SFSafariWindow, validationHandler: @escaping ((Bool, String) -> Void)) {
Task {
await printOpenTabsHost(in: window)
}
validationHandler(true, "")
}
override func popoverViewController() -> SFSafariExtensionViewController {
return SafariExtensionViewController.shared
}
}
Could you please tell if i'm missing something and how to see the actual tabs inside the overridden validateToolbarItem call of the SafariExtensionHandler (or in any other way, I'm okay with any implementation as long as it works).
Consider this code:
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
EmptyView()
}
}
}
Which looks like this:
How can I prevent the sidebar from being resized by a mouse and from being hidden?
P.S. Can consider using AppKit if it can help.
How can I put one list item at the top and another one at the bottom, retaining the NavigationView functionality?
Here is a simple app:
struct ContentView: View {
var body: some View {
NavigationView {
Sidebar()
}
}
}
struct Sidebar: View {
@State private var isActive = true
var body: some View {
List {
NavigationLink(isActive: $isActive) {
HomeView()
} label: {
Text("Home")
}
NavigationLink {
SettingsView()
} label: {
Text("Settings")
}
}
}
}
struct HomeView: View {
var body: some View {
VStack {}
.navigationTitle("Home")
}
}
struct SettingsView: View {
var body: some View {
VStack {}
.navigationTitle("Settings")
}
}
Which looks like this:
My initial though was to put a Spacer() between each NavigationLink, but it results in an unexpected view:
What i can do:
Place an empty VStack between each NavigationLink with a hard-coded height like this:
VStack {}.frame(height: 275)
Which looks like this:
But it wouldn't work if a user would want to increase the height of a window.
I could disable window resizing which is kind of fine, but not the most optimal.
Another obvious option was to replace the List with a VStack, but with this approach the styling of the NavigationLink gets broken and it does not get highlighted when I click on it.
It looks like this:
P.S. I know that NavigationView is deprecated, but i want to support macOS 12.0.
I have a Safari App Extension which allows users to switch between last open tabs with a shortcut option+tab in the same way it's possible to switch between last open apps with command+tab.
Here is how i do it:
I inject a content script on all websites which has the only thing – key listener for option+tab presses.
When a user presses option+tab, that keyboard listener detects it and sends a message to the Safari Handler.
Then Safari Handler sends a message to the containing app and it shows a panel with last open tabs.
This approach has a problem: it shows a message to a user in settings: "Can read sensitive info from web pages, including passwords..."
Which is bad, because in reality i don't read passwords.
If i remove SFSafariContentScript key in the Safari App Extension target's Info.plist, then this message about reading sensitive data disappears, but then i loose the ability to open the tabs panel.
How can I open my app window with a shortcut without frightening a user?
It's possible to listen to global key presses, but that would require a user to grant the app permissions of Accessibility (Privacy & Security) in macOS system settings, which also sounds shady.
I know an app which does not require an Accessibility permission: https://apps.apple.com/ua/app/tabback-lite/id6469582909 and at the same time it does not tell a user about reading sensitive data in the extension settings.
Here is my app: https://apps.apple.com/ua/app/tab-finder/id6741719894 It's open-source: https://github.com/kopyl/safari-tab-switcher
Sometimes the Safari App Extension i'm developing does not show up in my Safari Extensions unless i change mu bundle identifier to some unique name.
Even if I delete all other apps i've built with the same (and different) bundle ID, the extension is still does not show up.
The only solution for me is to always change the bundle ID.
For example:
Now it is "kopyl.tab-finder-10"
If i change it to "kopyl.tab-finder-11", the extension does show up in the Safari extensions settings page again.
Is there any other way to fix it?