Workaround for didReceiveRemoteNotification not getting called in foreground on iOS 11

When your iOS application receives a push notification while in foreground, the didReceiveRemoteNotification method in the application’s AppDelegate gets called. You get the whole push notification payload and you can react to it. But there is a problem introduced in iOS 11, then fixed and then broken again (like many things done by Apple these days) that didReceiveRemoteNotification does not get called when a push notification arrives and the application is in foreground. This can be really bad if your application depends on reliable push notifications while running.

The worst thing about this problem is that everything seems to be working while you are debugging the application from XCode. The method gets called, the payload is available. But when you open the application in your iPhone or iPad without the debugger attached, didReceiveRemoteNotification just never gets called. There are many developers reporting this problem on the Apple forums and on StackOverflow.

[Read More]

Preventing Windows drives from getting automatically mounted on macOS

If you run macOS side by side with Windows or have some drives formated with NTFS, you may not want them to get automatically mounted when you start macOS. I have a Windows 10 SSD with NFTS and a data HDD with NTFS next to my macOS SSD and I do not use any o those two drivers when booted in macOS, so I was looking for a way to have them not mounted at startup.

The main reason for this other than them not being shown in Finder is that macOS spins the data HDD from time to time for no apparent reason and I really do not want this.

In a classic Linux system you could edit /etc/fstab. This file can be also created on macOS, but Apple does not recommend editing it directly but to use sudo vifs. The drives should be addressed by their UUID as opposed to their “location” on Linux, so you first have to find that UUIDs.

When you have the drivers mounted, run diskutil info /Volumes/"Volume name" | grep 'Volume UUID' where “Volumne name” is the volume name as shown in Finder. This will get you just the UUID.

[Read More]

My experience with Swift after 9 months

About 9 months ago I basically left the world of Windows development because of the death of Windows Phone and me being really fed up with Microsoft. I got a chance to work on a complete native rewrite of an iOS application so I turned my desktop PC into a hackintosh and started learning Swift and iOS development.

This post describes my experience and feelings about Swift, the language, tooling, resources after 9 months. I will probably write another post about my experience with iOS development and the iOS community.

Swift language

I think Swift is a nice modern language, it reminds me of a combination of C# and F#, so two languages I really like. The introduction of Swift got me first thinking about switching to iOS development, Windows Phone was already dying at that time.

I tried iOS development with Objective-C some time ago, did some tutorials but the language just felt wrong. Not only the strange syntax, I do not really care about that, but the expressiveness of the language compared to C#. I had to write so much more code to do anything. Swift is just much better with that.

As a side note I remember reading Masterminds of Programming a few years back, the interview with one of Objective-C authors and his hate about C++ saying he did everything better that Stroustrup and thinking “I really do not like this guy” (I do not remember if it was Cox or Love).

[Read More]

Using Visual Studio Code as Git merge tool

Visual Studio Code is a neat editor with many good functionalities but I especially like the way it shows Git merge conflicts. Instead of a 2-way or a 3-way split it just shows one window with both changes, nicely highlighted with colors and actions.

I like this feature so much I decided to set Visual Studio Code as my Git merge tool for both the command line and Git Tower.

Command line

Using Visual Studio Code as a merge tool for Git when using command line means editing your .gitconfig. You just need to define a new tool called code and set it as the default merge tool.

[Read More]

Filling UITableView with data from bottom to top

If you work on something like an chat app, you may need to use the UITableView in a way where data is filled from bottom to top. An example of this is a chat detail screen, where you want the UITableView to show the latest messages at the bottom when loaded, new messages are added to the bottom and immediately shown and older messages are loaded on top when the user scrolls to the top of the UITableView.

There are multiple ways to achieve this, each with some advantages and disadvantages.

Scrolling

The first simplest idea that comes to mind is using the UITableView as is and just scrolling it when necessary:

  • Scroll to bottom when the initial messages are loaded
  • Scroll to bottom when a new message is added
  • When older messages are about to be added to the top, remember the position, add the older messages, scroll back to that position

The first two situations are easy to accomplish, but the last one is not. I could not find a way to make it works without a visible scrolling effect.

Rotating UITableView 180 degrees

Another solution is to rotate the UITableView by 180 degrees; rotating it upside down. Of course you have to also “flip” your data source but that is trivial to achieve. The advantage is that you do not have to do any scrolling when new messages are added to the bottom (which is the top of the rotated UITableView) and if you use batch updates instead of reload neither when older messages are loaded.

[Read More]

More readable XCode build output for CI

If you use Continuous Integration (CI) builds or build your app from the command line using xcodebuild you know that the output is not pretty and not very readable. Reading the build output is important when a CI build breaks, but it is not easy when it looks like this

Many iOS developers were not satisfied with this so the xcpretty project was created. Xcpretty is a fast and flexible formatter that turn the output from screnshot above to this neatly formatted output

[Read More]

iOS tip: Wireless debugging from XCode

One of the best XCode 9 features is the ability to deploy and debug iOS app on your device over WiFi, with no need to have the device connected to you computer by a cable. The only requirement is that the device runs iOS 11.

Setting it up is really easy. Connect the device using a cable like you normally do and go to Window | Devices and Simulators. You will see a new checkbox next to your iOS 11 devices called Connect via Network (see screenshot below), so check it. Now you can disconnect the cable and debug on your device over WiFi, the device has to be on the same network as your computer of course.

[Read More]

Fixing black artifact when changing large titles mode in iOS11

One of the new features of iOS 11 is the ability to display large headers in the navigation bar by setting the prefersLargeTitles property to true. You can set it for the whole app (using the UIAppearance for example) or differently for each view controller.

But there is a problem. If you navigate from a view controller with large titles enabled to a view controller with large titles disabled, you will see a black artifact under the change animation:

The black artifact comes from the navigation controller. If you set the backgroundColor of the navigation controller’s view to any, like red, it will replace the black artifact with an artifact of that color. The solution is to set the color of the color of you UI, white in my case:

[Read More]

Fixing problems with iPhone USB tethering on macOS

When my ISP had a problem resulting in Internet outage for multiple hours and I needed to work, I wanted to tether the LTE connection from my iPhone 6S to my hackintosh running macOS Sierra. It has no Wi-Fi card so the only was was tethering over USB cable.

The whole process should be easy, just connecting the iPhone to the computer with an USB cable and turning on the Personal hotspot in the Settings. The iPhone immediately registered 1 connection, but Internet did not work on the computer, although everything looked fine in System Preferences

[Read More]

Creating a dropdown menu from iOS navigation bar

Working on an iOS app I had to implement a filter for the table view displayed on screen. The filter should have contained 5 items and be accessible when tapping the screen title in the navigation bar. My first idea was to use an UIAlertController with those 5 options. It worked but it looked really ugly, So I started searching for a better, nicer solution. Ideally some kind of a dropdown menu.

I found multiple libraries for an iOS dropdown menu, but I liked BTNavigationDropdownMenu the best. The usage is really simple. First you define the items for the dropdown as an string array

create the menu instance

[Read More]