Post

Replies

Boosts

Views

Activity

Reply to How To Shutdown M1 Mac From Keyboard
this isn't really a developer question, you would have more luck asking this on the support forums. You could get an external keyboard with a media eject key, then you can use the shortcuts listed here https://support.apple.com/en-us/HT201236. Or, hold down the Touch ID/power button until the machine shuts down. Or, just close the lid and let the Mac sleep. Unlike Intel Macs, M1 Macs keep their charge for quite a while in sleep.
Topic: App & System Services SubTopic: Core OS Tags:
Oct ’22
Reply to DriverKit code signing/driver loading issues.
I also spent weeks battling signing issues. If you're using Xcode 14, you can simply select "Automatic" in the Signing and Capabilities tab. As it says in that tab, "Xcode will create and update profiles, app IDs and certificates". Choose "Development" for the signing certificate. Delete any app IDs or profiles you may have made manually on the developer portal for your app or its extension, and let Xcode do all the work for you. If you don't, Xcode will try to use the manually generated profiles and you'll get a message like "Xcode 14 and later requires a DriverKit development profile enabled for IOS and macOS. Visit the developer website to create or download a DriverKit profile". Automatic signing will let you develop and test on your own machine, or any other test machine entered on the portal under Devices. You asked "Does the Code Signing Identity/Profile in the Apple Developer section need to match exactly, or can that have more than what is requested? " If you look at the embedded profile that Xcode puts in your app, you'll see what it creates (for development). It looks at the entitlements you request, and puts those same entitlements in the profile. In my case I have a com.apple.developer.driverkit.transport.usb entitlement which specifies my company's USB vendor ID. The development embedded profile specifies "*" as the vendor ID, the distribution profile specifies my company's VID. When you come to distribute your app, Xcode can't create everything for you. The Account Owner has to go into the portal and create profiles for any extensions which require managed capabilities (entitlements which are only provided in response to a specific request to Apple). An Admin can create other types of profiles. If you are not the Account Owner the Generate button will fail to generate a profile, but it won't tell you why. In the distribution workflow, you choose the manually-generated profiles when you come to upload your product for notarization (not at build time). So you can keep the "Signing and Capabilities" setting in Xcode at Automatic.
Topic: App & System Services SubTopic: Drivers Tags:
Oct ’22
Reply to Special camera application issue
well, that looks like a fun application! Aren't you just seeing normal lens vignetting here? The image plane of the original film camera was evenly illuminated by the original lens (film cameras can't compensate for lens vignetting). The adapter interposes elements between that image plane and the iPhone's lens, such that light falling on the periphery of the plane follows a much different path than light falling on the center of the plane. You can and should compensate for the difference in image brightness in software.
Topic: App & System Services SubTopic: Core OS Tags:
Oct ’22
Reply to Need Help
In Xcode, choose File/New... Project. From the template chooser, select macOS, Application, Command Line Tool. Click Next give it a name (maybe "hello") choose C++ from the language popup click Next choose where to save your project Xcode will open the project and it will have a starter main() routine. Xcode help is here https://developer.apple.com/documentation/xcode This will get you started. After that, this forum, and the Internet in general, is your friend. Most of the differences between Mac and Windows are in the application and system frameworks and APIs. But you'll face an uphill struggle with programming on the Mac if you insist on using C++, because most of the APIs are Objective C or Swift, and some of the new frameworks are Swift-only.
Oct ’22
Reply to macOS Shortcut stuck halfway
answering my own post here. It was something extremely simple - I hadn't actually implemented - (nullable id)application:(NSApplication *)application handlerForIntent:(INIntent *)intent in the app delegate. I had implemented something like it but spelled it wrong. I still don't know how an "App Intent" differs from an intent in a .intentdefinition file.
Topic: App & System Services SubTopic: Core OS Tags:
Oct ’22
Reply to NoSleep for Mac
You haven't said why you want to do this, but here are some suggestions System Preferences/Battery, set the machine to not sleep and not send the display to sleep 'man pmset' favorite search engine - "Caffeine macOS"
Topic: Safari & Web SubTopic: General Tags:
Oct ’22
Reply to Save items from userdefault are not deleted even-though deleting the macOS app.
you are correct. The behavior might be different for sandboxed apps (I don't know, I don't write or maintain any). But why is this a problem for you? During testing, you should delete any old preferences or user data, to simulate the first-install scenario. Users may install your app, try it out, delete it and then re-install it years later. During that time, your preferences may have changed, and you have to account for that. If you want every install for end users to be like the first install, you can use an installer rather than drag-and-drop. The installer script can delete any lingering preferences before installation. You might also be able compare the 'date added' of your app to a timestamp you write into your preferences at first launch. If your app is now in /Applications, and was put there after the timestamp in your preferences, it has been run before (from somewhere), and you may want to clear the preferences to first-run default values. I believe the 'date added' attribute is only readable by parsing the result of a Spotlight query.
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’22
Reply to Windows Developer moving to macOS – please help me to start
You certainly can use C++ in macOS apps. By default, Xcode will compile files with a .m extension as Objective C, and with a .mm extension as Objective C++. You can also select individual files in your project and tell Xcode to use a different compiler than the default, but I'd advise against this. However, you'll notice that nearly all current Apple sample code is in Swift. Most of the hints and tips you'll find on the Internet will be for Swift. Any samples in Objective C are often out of date. It isn't impossible to figure out what to do, but it is an additional hurdle. There is a macOS GUI API, it is called AppKit for macOS. There's another similar one for iOS called UIKit. Again, you'll find the majority of posts on Apple programming are for iOS and UIKit, because there are far more phones out there than desktops. You can call into AppKit from ObjC or ObjC++ or Swift. If you have cross-platform library code written in C++ you can use that in a Swift or ObjC/C++ app, but you'll need to give it a C interface. I don't think VS code can generate a macOS app (it can generate an iOS app), but I could be wrong. You can certainly run VS for Mac on your Mac, and use its editor if you're more comfortable with that. You can run Xcode from the command line if you want to fire off a build from VS, but Xcode integrates a debugger and I don't know how that would work in VSCode (for a macOS app). A lot of the work in producing a shippable app isn't in the code itself, it is in localization, testing, packaging, signing and notarizing. Xcode can help with that. Swift was introduced in 2014, it is quite mature now. If I were starting something brand new for macOS, I'd certainly write it in Swift. If you're used to one platform and move to another, you'll find many things are different. The platforms are different, the user expectations are different and the tools and frameworks are different. Embrace that.
Topic: App & System Services SubTopic: Core OS Tags:
Sep ’22
Reply to Trying to make an expandable table in Swift using API calls
My first advice would be don't try to work with expandable TableView cells if you're new to Swift, Table Views etc. Tables with varying height and content are a pain. The request is that a tap on a school shows more information about that school. So add a detail view segue when you tap on a table item, and have that detail view display all the detailed school information. On the phone, that will take up an entire screen, with a back button on the top left, you'll put the name of the school in the top middle and you have a whole lot of space to display the per-school details on their own, outwith the table. There are a whole lot of tutorials on displaying varying levels of database detail for iOS using more prosaic information display methods.
Topic: UI Frameworks SubTopic: UIKit Tags:
Jul ’22
Reply to Detecting background volume level in Swift
Read up on "noise gates". The audio samples are PCM float values between -1.0 and 1.0. That's the instantaneous value of the signal amplitude in the channel, it cannot exceed maximum volume. Values close to 0.0 are very quiet. Assuming your microphone is correctly set up, when you speak loudly, close to the microphone, the peak signal amplitude will be close to 1.0. A background noise might be 30 to 40dB below this, or at a level of about 0.03 to 0.01. A reasonable noise gate might want to measure the input values and cut any sound at or below this level, if it persists, while it would permit sound above this level, again if it persists. A reasonable noise gate usually turns on quickly (so you don't cut off the beginning of speech) and turns off slowly (so you don't have abrupt cut-offs which can sound jarring). The first sample uses vDSP_meamvg, which is documented here: https://developer.apple.com/documentation/accelerate/1449731-vdsp_meamgv It isn't clear what LEVEL_LOWPASS_TRIG is supposed to be. It might be a value between 0 and 1. Its name suggests it is a trigger value (i.e. a threshold for the noise gate) but it seems to be used here to adjust how rapidly the averagePowerForChannel variables approach the measured value in a single buffer. The second sample is easier to comprehend. It takes every incoming sample (a floating point value between -1 and +1) and finds its absolute value. If the current rectified sample is larger than the 'envelopeState', the envelopeState is increased by 0.16 of the difference, while if it is smaller the envelopeState is decreased by 0.03 of the difference. So 'envelopeState' will rapidly rise if there is input, and slowly fall if there is none, or if the volume of that input falls below that of 'envelopeState'. The routine uses the peak value of an array of 'envelopeState' values as a gate. The buffer is considered full of background noise only if that peak value is less than 0.015. Remember envelopeState isn't an absolute signal level, it is a filtered difference value. hope this helps.
Topic: Programming Languages SubTopic: Swift Tags:
Jul ’22
Reply to Is there a way to remove system extension without rebooting the device?
I certainly haven't found a way to replace a running system extension (in my case, a Camera Extension), without rebooting. I don't know how this is supposed to be communicated to end users, because the impression given by Apple is that if they update your app (with its built-in extensions), that the extensions are automatically updated. They are, but only at the next reboot. If you make a protocol change such that App version N only works with Extension version N, but not Extension version N-1, you'll have to tell the user that they need to reboot. The OS won't tell the user.
Topic: App & System Services SubTopic: Drivers Tags:
Jul ’22
Reply to How To Shutdown M1 Mac From Keyboard
this isn't really a developer question, you would have more luck asking this on the support forums. You could get an external keyboard with a media eject key, then you can use the shortcuts listed here https://support.apple.com/en-us/HT201236. Or, hold down the Touch ID/power button until the machine shuts down. Or, just close the lid and let the Mac sleep. Unlike Intel Macs, M1 Macs keep their charge for quite a while in sleep.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Oct ’22
Reply to DriverKit code signing/driver loading issues.
I also spent weeks battling signing issues. If you're using Xcode 14, you can simply select "Automatic" in the Signing and Capabilities tab. As it says in that tab, "Xcode will create and update profiles, app IDs and certificates". Choose "Development" for the signing certificate. Delete any app IDs or profiles you may have made manually on the developer portal for your app or its extension, and let Xcode do all the work for you. If you don't, Xcode will try to use the manually generated profiles and you'll get a message like "Xcode 14 and later requires a DriverKit development profile enabled for IOS and macOS. Visit the developer website to create or download a DriverKit profile". Automatic signing will let you develop and test on your own machine, or any other test machine entered on the portal under Devices. You asked "Does the Code Signing Identity/Profile in the Apple Developer section need to match exactly, or can that have more than what is requested? " If you look at the embedded profile that Xcode puts in your app, you'll see what it creates (for development). It looks at the entitlements you request, and puts those same entitlements in the profile. In my case I have a com.apple.developer.driverkit.transport.usb entitlement which specifies my company's USB vendor ID. The development embedded profile specifies "*" as the vendor ID, the distribution profile specifies my company's VID. When you come to distribute your app, Xcode can't create everything for you. The Account Owner has to go into the portal and create profiles for any extensions which require managed capabilities (entitlements which are only provided in response to a specific request to Apple). An Admin can create other types of profiles. If you are not the Account Owner the Generate button will fail to generate a profile, but it won't tell you why. In the distribution workflow, you choose the manually-generated profiles when you come to upload your product for notarization (not at build time). So you can keep the "Signing and Capabilities" setting in Xcode at Automatic.
Topic: App & System Services SubTopic: Drivers Tags:
Replies
Boosts
Views
Activity
Oct ’22
Reply to Special camera application issue
well, that looks like a fun application! Aren't you just seeing normal lens vignetting here? The image plane of the original film camera was evenly illuminated by the original lens (film cameras can't compensate for lens vignetting). The adapter interposes elements between that image plane and the iPhone's lens, such that light falling on the periphery of the plane follows a much different path than light falling on the center of the plane. You can and should compensate for the difference in image brightness in software.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Oct ’22
Reply to Need Help
In Xcode, choose File/New... Project. From the template chooser, select macOS, Application, Command Line Tool. Click Next give it a name (maybe "hello") choose C++ from the language popup click Next choose where to save your project Xcode will open the project and it will have a starter main() routine. Xcode help is here https://developer.apple.com/documentation/xcode This will get you started. After that, this forum, and the Internet in general, is your friend. Most of the differences between Mac and Windows are in the application and system frameworks and APIs. But you'll face an uphill struggle with programming on the Mac if you insist on using C++, because most of the APIs are Objective C or Swift, and some of the new frameworks are Swift-only.
Replies
Boosts
Views
Activity
Oct ’22
Reply to macOS Shortcut stuck halfway
answering my own post here. It was something extremely simple - I hadn't actually implemented - (nullable id)application:(NSApplication *)application handlerForIntent:(INIntent *)intent in the app delegate. I had implemented something like it but spelled it wrong. I still don't know how an "App Intent" differs from an intent in a .intentdefinition file.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Oct ’22
Reply to NoSleep for Mac
You haven't said why you want to do this, but here are some suggestions System Preferences/Battery, set the machine to not sleep and not send the display to sleep 'man pmset' favorite search engine - "Caffeine macOS"
Topic: Safari & Web SubTopic: General Tags:
Replies
Boosts
Views
Activity
Oct ’22
Reply to Save items from userdefault are not deleted even-though deleting the macOS app.
you are correct. The behavior might be different for sandboxed apps (I don't know, I don't write or maintain any). But why is this a problem for you? During testing, you should delete any old preferences or user data, to simulate the first-install scenario. Users may install your app, try it out, delete it and then re-install it years later. During that time, your preferences may have changed, and you have to account for that. If you want every install for end users to be like the first install, you can use an installer rather than drag-and-drop. The installer script can delete any lingering preferences before installation. You might also be able compare the 'date added' of your app to a timestamp you write into your preferences at first launch. If your app is now in /Applications, and was put there after the timestamp in your preferences, it has been run before (from somewhere), and you may want to clear the preferences to first-run default values. I believe the 'date added' attribute is only readable by parsing the result of a Spotlight query.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’22
Reply to Windows Developer moving to macOS – please help me to start
You certainly can use C++ in macOS apps. By default, Xcode will compile files with a .m extension as Objective C, and with a .mm extension as Objective C++. You can also select individual files in your project and tell Xcode to use a different compiler than the default, but I'd advise against this. However, you'll notice that nearly all current Apple sample code is in Swift. Most of the hints and tips you'll find on the Internet will be for Swift. Any samples in Objective C are often out of date. It isn't impossible to figure out what to do, but it is an additional hurdle. There is a macOS GUI API, it is called AppKit for macOS. There's another similar one for iOS called UIKit. Again, you'll find the majority of posts on Apple programming are for iOS and UIKit, because there are far more phones out there than desktops. You can call into AppKit from ObjC or ObjC++ or Swift. If you have cross-platform library code written in C++ you can use that in a Swift or ObjC/C++ app, but you'll need to give it a C interface. I don't think VS code can generate a macOS app (it can generate an iOS app), but I could be wrong. You can certainly run VS for Mac on your Mac, and use its editor if you're more comfortable with that. You can run Xcode from the command line if you want to fire off a build from VS, but Xcode integrates a debugger and I don't know how that would work in VSCode (for a macOS app). A lot of the work in producing a shippable app isn't in the code itself, it is in localization, testing, packaging, signing and notarizing. Xcode can help with that. Swift was introduced in 2014, it is quite mature now. If I were starting something brand new for macOS, I'd certainly write it in Swift. If you're used to one platform and move to another, you'll find many things are different. The platforms are different, the user expectations are different and the tools and frameworks are different. Embrace that.
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Sep ’22
Reply to Trying to make an expandable table in Swift using API calls
My first advice would be don't try to work with expandable TableView cells if you're new to Swift, Table Views etc. Tables with varying height and content are a pain. The request is that a tap on a school shows more information about that school. So add a detail view segue when you tap on a table item, and have that detail view display all the detailed school information. On the phone, that will take up an entire screen, with a back button on the top left, you'll put the name of the school in the top middle and you have a whole lot of space to display the per-school details on their own, outwith the table. There are a whole lot of tutorials on displaying varying levels of database detail for iOS using more prosaic information display methods.
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
Jul ’22
Reply to Detecting background volume level in Swift
Read up on "noise gates". The audio samples are PCM float values between -1.0 and 1.0. That's the instantaneous value of the signal amplitude in the channel, it cannot exceed maximum volume. Values close to 0.0 are very quiet. Assuming your microphone is correctly set up, when you speak loudly, close to the microphone, the peak signal amplitude will be close to 1.0. A background noise might be 30 to 40dB below this, or at a level of about 0.03 to 0.01. A reasonable noise gate might want to measure the input values and cut any sound at or below this level, if it persists, while it would permit sound above this level, again if it persists. A reasonable noise gate usually turns on quickly (so you don't cut off the beginning of speech) and turns off slowly (so you don't have abrupt cut-offs which can sound jarring). The first sample uses vDSP_meamvg, which is documented here: https://developer.apple.com/documentation/accelerate/1449731-vdsp_meamgv It isn't clear what LEVEL_LOWPASS_TRIG is supposed to be. It might be a value between 0 and 1. Its name suggests it is a trigger value (i.e. a threshold for the noise gate) but it seems to be used here to adjust how rapidly the averagePowerForChannel variables approach the measured value in a single buffer. The second sample is easier to comprehend. It takes every incoming sample (a floating point value between -1 and +1) and finds its absolute value. If the current rectified sample is larger than the 'envelopeState', the envelopeState is increased by 0.16 of the difference, while if it is smaller the envelopeState is decreased by 0.03 of the difference. So 'envelopeState' will rapidly rise if there is input, and slowly fall if there is none, or if the volume of that input falls below that of 'envelopeState'. The routine uses the peak value of an array of 'envelopeState' values as a gate. The buffer is considered full of background noise only if that peak value is less than 0.015. Remember envelopeState isn't an absolute signal level, it is a filtered difference value. hope this helps.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Jul ’22
Reply to Is there a way to remove system extension without rebooting the device?
I certainly haven't found a way to replace a running system extension (in my case, a Camera Extension), without rebooting. I don't know how this is supposed to be communicated to end users, because the impression given by Apple is that if they update your app (with its built-in extensions), that the extensions are automatically updated. They are, but only at the next reboot. If you make a protocol change such that App version N only works with Extension version N, but not Extension version N-1, you'll have to tell the user that they need to reboot. The OS won't tell the user.
Topic: App & System Services SubTopic: Drivers Tags:
Replies
Boosts
Views
Activity
Jul ’22