I have an app for ipad/iphone, now adding also mac support by Mac
Catalyst. On Mac, I want to control window resizing, in order to allow
only some sizes and aspects. It goes beyond simple minimal height and
weight, or aspect. I want to allow user to resize window freely, but
when it gets too high and narrow, I want to also seemlessly increase
width, to keep some minimal aspect.
I believe that in AppKit it can be done through
NSWindowDelegate.windowWillResize() (get user defined size, count
required size and return it). However I am getting error
"NSWindowDelegate is unavailable in Mac Catalyst" . Is it possible to
achieve the result I want by Catalyst means?
Post
Replies
Boosts
Views
Activity
Hi, I have Mac catalyst app, that usually shows one window, but under some circumstances I open another one with different content (so it is multi-windowed app, but not in a way of opening several documents in instances of the same type of window). I did manage to setup SceneDelegate, open scenes etc., but I have still some problems.
After app launch, old scenes are automatically recreated. Is there a way to stop it? I want to always start with main scene, and only open the second one from code.
Is there a way to set size and position of a window before it is shown? I can do it by acquiring NSWindow from UIWindow and then using AppKit from another bundle. But this can only be done after the window appears on screen. As a result, user sees window "jump".
When scene is being created (or maybe just recreated to restore previous session), window gets the same position it had before. Is there any way to control it? How this mechanism exactly works? Where are the previous positions stored and can they be modified? How a newly created scene gets its size and position?
On MacOS (catalyst app, but AppKit bundle) I am creating Share submenu in main app menu "on fly" from menu delegate like this:
func menuWillOpen(_ menu: NSMenu) {
self.provider = NSItemProvider(contentsOf: url)! //url points to existing temporary file of type .png
menu.removeAllItems()
let srvcs = NSSharingService.sharingServices(forItems: [self.provider!])
for srv in srvcs {
let it = NSMenuItem(title: srv.menuItemTitle, action: #selector(openSharingService), keyEquivalent: "")
it.image = srv.image
it.representedObject = srv
it.target = self
menu.addItem(it)
}
}
@objc private func openSharingService(sender: NSMenuItem) {
let service = (sender.representedObject as! NSSharingService)
service.perform(withItems: [self.provider!])
}
It works well for any share type, except for Send To Photos. With Send To Photos, I am getting this error in console:
>
2021-10-27 08:59:02.042220+0200 Calculator2[14383:7732689] [xpc.exceptions] <NSXPCConnection: 0x6000008470c0> connection to service on pid 14388 named com.apple.share.System.add-to-iphoto.apple-extension-service: Exception caught during decoding of received selector _completeRequestReturningItems:forExtensionContextWithUUID:completion:, dropping incoming message.
Exception: Exception while decoding argument 0 (#2 of invocation):
Exception: value for key 'NS.objects' was of unexpected class 'NSURL (0x7fff801889e8) [/System/Library/Frameworks/CoreFoundation.framework]'. Allowed classes are '{(
"NSDate (0x7fff80188600) [/System/Library/Frameworks/CoreFoundation.framework]",
"NSString (0x7fff801ba8d0) [/System/Library/Frameworks/Foundation.framework]",
"NSNumber (0x7fff801ba3a8) [/System/Library/Frameworks/Foundation.framework]",
"NSData (0x7fff801885d8) [/System/Library/Frameworks/CoreFoundation.framework]",
"NSDictionary (0x7fff80188650) [/System/Library/Frameworks/CoreFoundation.framework]",
"NSArray (0x7fff80188510) [/System/Library/Frameworks/CoreFoundation.framework]"
)}'.
Photos app is opened and image is added to it, but my app recieves
the above error and its menus are all grayed out until restarted. Am I
doing something wrong here?
We are making Safari extension for MacOS, that uses SFSafariApplication.dispatchMessage() to communicate between native and javascript parts of extension. Until recently everything worked, however after update to xcode 16 I started getting this error:
'dispatchMessage(withName:toExtensionWithIdentifier:userInfo:completionHandler:)' is unavailable in application extensions for macOS: Not available to extensions
'dispatchMessage(withName:toExtensionWithIdentifier:userInfo:completionHandler:)' has been explicitly marked unavailable here (SafariServices.SFSafariApplication)
I looked into documentation, however I did not find any hint of dispatchMessage() being replaced by something else. According to https://developer.apple.com/documentation/safariservices/messaging-between-the-app-and-javascript-in-a-safari-web-extension this is the way communication should be done.
Is it a bug? Or can someone direct me to working alternative of communication?
I am building Safari extension. In my background script I am setting badge text and title like this:
browser.action.setBadgeText({text: badgeText, tabId: tabId});
browser.action.setTitle({title: badgeText + " found images", tabId: tabId})
, where tabId is correct id of current tab.
I was expecting that in this way I am setting a different badge and title for different tabs, so that badge and title would automatically switch if I activate different tab. However this does not happen, badge and title behave as if set globaly and don't change with tabs. How is this expected to work?
I have also tried to set badge globally, and update it every time user switches a tab. I have set up listener like this:
browser.tabs.onActivated.addListener(function(actInfo) {
console.log("switched tab to " + actInfo.tabId);
});
, however the event never fires, tab switch is never logged in console.
Am I doing something wrong here?
This is my manifest, if there was a problem with permissions or something similar.
{
"manifest_version": 3,
"default_locale": "en",
"name": "Test",
"description": "Test Extension",
"version": "1.0",
"icons": {
"48": "images/icon-48.png",
"96": "images/icon-96.png",
"128": "images/icon-128.png",
"256": "images/icon-256.png",
"512": "images/icon-512.png"
},
"action": {
"default_title": "a test title",
"default_popup": "popup/hello.html",
"default_icon": {
"16": "images/toolbar-icon-16.png",
"19": "images/toolbar-icon-19.png",
"32": "images/toolbar-icon-32.png",
"38": "images/toolbar-icon-38.png",
"48": "images/toolbar-icon-48.png",
"72": "images/toolbar-icon-72.png"
}
},
"web_accessible_resources": [
{
"matches": ["*://*/*"],
"resources": ["images/*", "css/*", "scripts/lib/*"]
}
],
"background": {
"service_worker": "scripts/background.js",
"type": "module"
},
"content_scripts":
[
{
"js": [
"scripts/content.js"
],
"matches": [
"http://*/*",
"https://*/*"
],
"css": ["css/style.css"],
"run_at": "document_end"
}
],
"permissions": [
"nativeMessaging", "tabs"
]
}