My iOS8 adventure as a Xamarin developer

With this post I sum up my experiences with iOS8 as a developer. If possible I will provide solutions and workarounds.

The release of iOS8 is really unfortunate for me. A lot of my demos have stopped working and it seems like there are some really annoying bugs in iOS8.

Update: Added working example for reachability

Update: Apple confirms bug in iOS8 Simulator regarding backgrounding.

Update: explanation for the NSUrlSession issue found!

Reachability does not work on iOS8 Release version

Up to iOS7.1 it was no problem detecting the current network connection status. As of iOS8 the “reachability” code no longer works. Googling showed me one post on StackOverflow from somebody who has the same problems.

When using NetworkReachability and trying to get the current network flags, only “0” is reported as long as my device has WiFi and Cellular. If I enable airplane mode, it remains 0. Disabling airplane mode switches it to the correct values and then immediately back to 0.

Update: I have create a Gist that shows some working code. The important part is to not use a specific host address but “new IPAddress(0)” instead. I used to check Google or the host address I would connect to but this gives me the (incorrect) behavior as described above.

Apple also confirmed they fixed some things around Reachability in iOS 8.0.2 (that was a misunderstanding. “Reachability Feature” is where double tapping the home button will move down the screen on iPhone 6 to allow one hand usage)

The Simulator has moved to a new location

It is now located at

/Users/rene/Library/Developer/CoreSimulator/Devices

From there on, each Simulator is identified via a GUID. So if you want to get to you’re application’s documents folder, it is something like:

/Users/rene/Library/Developer/CoreSimulator/Devices/[SIMULATOR GUID]/data/Containers/Data/Application/[APPLICATION GUID]/Documents

It also seems like folder names keep on changing every time an app gets launched. There’s a post about the whole topic here.

NSUrlSession does not work

It seems like NSUrlSession is broken. When specifying an NSUrlSessionDownloadDelegate, the method URLSessionDidFinishEventsForBackgroundURLSession:
(or DidFinishEventsForBackgroundSession (NSUrlSession session) in Xamarin) will never be called.

The reason for this seems to be that there is always one entry left in the download queue. The topic is discussed in the Apple forums here and there and on StackOverflow.

Found out today (24 September, 2014): Okay, now I have clear visison…man, too many concurrent issues here. So, here’s the full explanantion of what’s going on.

First we have to know:

  • The iOS8 Simulator has a bug that prevents apps from truly being backgrounded. They just continue to run.
  • iOS8 requires the registration of notification types. My file transfer app wants to show a local notification when all files have been downloaded.
  • When using NSUrlSession, URLSessionDidFinishEventsForBackgroundURLSession will only be triggered if the app is backgrounded or not running.
The combination of these three created a complex test scenario.
  • Eskimo’s demo (from the Apple dev forums) works on the iOS8 device because it is just doing a file transfer without any UI interaction like notifications.
  • My demo seems to not work on the device because it was not registering the local notification, hence the notification would be shown and therefore I presumed it did not work.
  • Neither of the demos work on the iOS8 Simulator because apps in the Simulator are never truly in background mode and so URLSessionDidFinishEventsForBackgroundURLSession won’t trigger.
  • Everything works on iOS7 devices and Simulators, because there is no Simulator bug and the local notification registration is not required.

Using CLLocationmanager fails

When using CLLocationManager in an app you now have to request permission from the user to do so. Here’s an article from James Montemagno that discusses the issue. Note that he is discussing iBeacons, but the same applies when using plain location data.

Text to Speech Synthesis does not work

Currently the text-to-speech APIs do not work in the iOS8 Simulator. Using AVSpeechUtterance.Speak() will result in an error in the output window. It works on the device at least.

Cannot deploy apps to the device

I have received a new iPhone and tries to use it for development. There used to be a checkbox in Xcode Organizer that would set a device into development mode and register it in the developer portal. This no longer exists. There is a new app called “Devices” but it does not have the feature either.

Instead devices have to be registered manually via the website. Alternatively, you can fire up Xcode, create a dummy app and deploy it to your connected device. Xcode will then offer you to fix the problem, which means it’ll do the portal registration for you.

Thanks Apple, for making this so intuitive…

Cannot run apps on iOS7 Simulator

When my Xcode 6 installation was done, it had removed all older Simulators and SDKs. In the Xcode 6 preferences I reinstalled the iOS7.1 Simulator. It shows up in Xamarin Studio’s drop down. However if I select it I simply get the error that deployment failed.

Threads are not suspended in the iOS Simulator when app is backgrounded

I seems like the threads are getting suspended when the app gets executed on a real device. However they keep on running on the Simulator. What is also very odd: the Simulator runs threads forever, unless you add call to beginBackgroundTask: – then it will give you 180 seconds just like expected and will also terminate the app after that time.

So are we facing a problem in the Simulator here? I don’t know anymore! Voices over on the Apple forums claim that this is a feature in order to keep the debugger attached. I cannot believe this. After all, the behavior has changed from Xcode 5 to Xcode 6.

There are news on this topic now: Apple has confirmed it is a bug. It is an issue with the Simulator.

Post Media Link

krumelur