Changing UIAlertAction text color

If you use the standard iOS UIAlertController to present the user with a list of actions, there is not much you can do about styling each of the UIAlertActions shown.

The text of the shown UIAlertAction uses the UIView’s tint color, so you can use the UIAppearence API to change it to any color you want, but the same color for all the UIAlertActions. If you set the style to destructive instead of default, the text is shown as red, not affected by the tint color.

UIAlertController with one default and one destructive action might then look like this with dark blue set as the global tint color using UIAppearence:

The red color for the destructive option does not look that great, especially if your app uses a different shade of red everywhere else.

If you dive deep into Apple documentation you will find a KVC called titleTextColor. This KVC allows you to set exactly what you need, the color for the UIAlertAction text.

[Read More]
iOS  Xcode 

Adding Wi-Fi and Bluetooth to hackintosh to enable Apple-specific features

When I started with my hackintosh I did not have Wi-Fi or Bluetooth support in it. I used Ethernet to connect to my home network and it worked fine, I had no need for Wi-Fi.

Later I wanted to use more “Apple-specific” features, so I started looking for how to make them work with my hackintosh.

Bluetooth

Adding Bluetooth support to a hackintosh is quite easy, you just need to buy any of these USB adapters:

All of them are natively supported in macOS, no extra drivers are needed.

GMYLE Bluetooth 4.0 Adapter

I bought the GMYLE Bluetooth 4.0 Adapter, found it on German Amazon.

Thanks to adding Bluetooth support I got:

  • Ability to use Bluetooth keyboards, speakers, headphones
  • SMS messages showing on macOS
  • incoming phone calls showing on macOS

The SMS relying feature was really nice, especially when needing to copy security codes sent by SMS by services that do not support 2FA via TOTP.

Justa s a side note, iMessage worked right from the start, Bluetooth is not needed for it.

Wi-Fi

Wi-Fi required for some Apple-specific features

The one thing that I was missing was AirDrop. I started taking screenshots regularly on my iPhone during development and testing and there was no easy way to move them to the hackintosh without AirDrop.

To make AirDrop and additional features like Handoff work you need not only Bluetooth but also an internal Wi-Fi card.

[Read More]

Editing macOS app About dialog

When you create a macOS app and keep the default menu, you automatically get an About dialog. This dialog shows basic info about the app.

If you want to add more information to this dialog there is no obvious way to do it. You need to start reading the Apple documentation to finally discover that it is actually quite simple.

[Read More]
macos  xcode 

Using CocoaPods to just build frameworks for use elsewhere

I am definitely not a fan of CocoaPods, I use Carthage in all of my projects. It is not ideal but I have a way of using it that works for me.

Recently I was faced with a problem that made me use CocoaPods but in a quite different way, just to build some frameworks to be used elsewhere without CocoaPods.

The problem

I use GRDB.swift to work with the database in iOS applications, especially because it support using SQLCipher to have the database encrypted. The current version 3.x has some problem when used by Xcode 10.2 and Swift 5 so using the latest 4.0 is recommend.

GRDB.swift never supported Carthage but there was always a way to make it work. I usually just needed to delete some of the shared schemes and run carthage build instead of carthage bootstrap. I was not able to make Carthage work with 4.0, mainly because the targets changed. There is no GRDBCipher target for use with SQLCipher anymore, just a podspec definition

  s.subspec 'SQLCipher' do |ss|
    ss.source_files = 'GRDB/**/*.swift', 'Support/*.h'
    ss.framework = 'Foundation'
    ss.dependency 'SQLCipher', '>= 3.4.0'
    ss.xcconfig = {
      'OTHER_SWIFT_FLAGS' => '$(inherited) -D SQLITE_HAS_CODEC -D GRDBCIPHER -D SQLITE_ENABLE_FTS5',
      'OTHER_CFLAGS' => '$(inherited) -DSQLITE_HAS_CODEC -DGRDBCIPHER -DSQLITE_ENABLE_FTS5',
      'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) SQLITE_HAS_CODEC=1 GRDBCIPHER=1 SQLITE_ENABLE_FTS5=1'
    }
end

It looks like only using CocoaPods and SwiftPM is now supported, there is not even an easy way to do manual installation.

I had to decide how to integrate 4.0 to my project in the best way possible.

[Read More]

Detecting click on a specific NSTableViewCell

When you use NSTableView in an macOS application, there is no direct way to know a specific NSTableViewCell was clicked by the user. In my Localization Editor project I wanted the user to be able to focus a NSTextField when clicking anywhere in the NSTableViewCell it is contained in, so I had to implement it myself.

I created a new delegate extending the NSTableViewDelegate with one additional method informing about a NSTableViewCell getting clicked

protocol NSTableViewClickableDelegate: NSTableViewDelegate {
    func tableView(_ tableView: NSTableView, didClickRow row: Int, didClickColumn: Int)
}

Then I added an extension to the NSTableView to compute the index of the clicked NSTableViewCell

extension NSTableView {
    open override func mouseDown(with event: NSEvent) {
        let localLocation = self.convert(event.locationInWindow, to: nil)
        let clickedRow = self.row(at: localLocation)
        let clickedColumn = self.column(at: localLocation)

        super.mouseDown(with: event)

        guard clickedRow >= 0, clickedColumn >= 0, let delegate = self.delegate as? NSTableViewClickableDelegate else {
            return
        }

        delegate.tableView(self, didClickRow: clickedRow, didClickColumn: clickedColumn)
    }
}

To be able to use this extension you just need to implement NSTableViewClickableDelegate instead of NSTableViewDelegate and use the additional method it provides.

macos  swift