"ios" entries

A brief introduction to Swift optionals.

Swift is becoming the language of choice for more and more developers on iOS and OS X. It’s fast, simple, clean, and has a number of features that simply aren’t available to Objective-C programmers.

While it isn’t a hard requirement to do so, several projects are being ported from Objective-C to Swift — especially those in their early stages — in order to take advantage of the speed, power, and safety of Swift. One of those projects isn’t actually a software project — it’s the upcoming Swift edition of iOS Games Programming Cookbook. When we began updating the book for Swift, the first thing that we had to do was to rewrite all of the book’s code in the new language. However, a straight re-write from one language into another isn’t enough. Swift behaves differently than Objective-C in very important ways, and that means that your ported Swift code needs to be aware of how Swift does things.

Large files in your app documents folder can earn you a rejection

There’s nothing worse than submitting your first app to the iTunes app store, and having it get rejected. Well, OK, there are plenty of things that are worse, but it still isn’t pleasant. Bounces can happen for a variety of reasons, from Apple not liking your app’s functionality to poorly written product descriptions and everything in between. But one recently new reason for rejections may catch you off guard, I know I was.

Now that iCloud can be used to back up app contents, Apple has become sensitive to apps that produce large amounts of documents in the app document folder. After all, if you dump 50MB of files into that folder, iCloud is going to try to back it all up, and it may suck up the user’s data plan usage. So, if you’re downloading and storing content as part of your app, you have to make sure that you mark it as not requiring backup to iCloud.

NSURLIsExcludedFromBackupKey flags the file as not requiring backup to iCloud. One important set of files that you should make sure you flag this way is any Core Data SQLite files that store significant amounts of data. For example, if you are storing images as blobs in your database, the file can get pretty big pretty fast.

It doesn't take many lines of code to make a snazzy animated background in iOS

One of nicest features of iOS development is that, frequently, you can pull off visual effects that look amazing without having to write a lot of code. It may be about to start the spring season here, but Down Under it’s heading into fall, so to honor those folks, we’ll animate some falling leaves. We’ll use a simple piece of code that will animate objects drifting down the screen.

I say drifting, because this trick only works for objects that are going to maintain a constant velocity as they descend through the space. Thus, it works well for things like leaves, pieces of paper, or other light objects that the mind will immediately accept as having reached their terminal velocity. In my case, I developed the code to handle confetti streaming down a “You’ve won” screen. Heavier or more streamlined objects require a bit more work to animate, because you need to simulate the effects of gravity and acceleration, otherwise the animation doesn’t look right.

So, to begin, we need some image assets. For this example, I’m going to use 3 leaf images I grabbed from a public clip art site, and cleverly renamed to leaf1.png, leaf2.png, and leaf3.png. I created a simple single-view storyboard project, and added a label in the center of the view. Now, all that’s left is to plop in the code:

Part One: Easily find Chromecast devices on your local network

Now that Google has opened up the Chromecast API for anyone to play with, it’s possibile to create iOS applications that can leverage the $35 device as a way to display to HDMI devices wirelessly. In this series of tutorials, we’ll go over the API, starting with configuring your project to use the framework, and finding devices out on your local network to play with.

Let’s assume you’ve set up a Chromecast device attached to an HDMI TV and have it configured for your local network. Now it’s time to get an App set up to use it. We’ll use the iPhone Simulator in these examples, since it can talk to Chromecast devices just like a physical device, as long as the Mac you are developing on is on the same LAN as the Chromecast dongle.

Begin by creating a project, as usual. For this example, I used a single-view Storyboarded app. I set up an UITableView inside the default UIView, hooking it’s datasource and delegate to the default view controller the wizard had created. Next, I went to the Google Google Cast API page and downloaded the iOS framework, then used the “Add Files…” project option to add the framework to the project, copying in the files.

RYO small floating view containing any interface you like

Of all the new features and APIs that iOS 7 provides to developers, none, in my opinion, is as important from a user interface perspective as custom view controller transitions, the ability to insert your own animation when a view controller’s view takes over the screen. Thus:

When a tab bar controller’s child is selected, you can now animate the change.

When a view controller is pushed onto a navigation controller’s stack, you are no longer confined to the traditional “slide in from the right” animation.

When a presented view controller’s view appears or is dismissed, you are no longer confined to a choice of the four UIModalTransitionStyle animations.

In the third case — a presented view controller — iOS 7 introduces a further innovation: You can position the presented view wherever you like, including the possibility of only partially covering the original interface.

In other words, the presented view controller’s view can float on top of, and partially reveal, the original view controller’s view; the user sees the views of both view controllers, one in front of the other.

Mobile developers to gain a new set of platforms for their apps

One of the perennial technologies that regularly appears at the Consumer Electronics Show is the smart TV set, but they never seem to gain the kind of traction that the manufacturers hope that they will. This may finally be coming to a end, however, as a new generation of smart TVs are poised to enter the market. Even Apple is finally supposed to release their own products in this space this year. And when these hyper-aware TV sets enter the Internet of Things, they are likely to do it running mobile operating systems.

The reasons for this are several. From a purely economic standpoint, the margins on televisions don’t really afford room to pay for a full-blown desktop operating system license, nor the hardware required to support a rich desktop environment. It’s also unclear that anyone would want to run Microsoft Word or other general types of software on their TV. While a free operating system such as a desktop Linux OS might fit the bill, especially since it is famous for being able to run on a meager amount of hardware, it is equally unclear if it will be able to run the software that manufacturers and users are going to want to see on a TV.

All predictions are for entertainment purposes only!

It is a generally accepted requirement that all technology pundits attempt a yearly prognostication of the coming 12 months. Having consulted my crystal ball, scryed the entrails of a falcon, and completed a 3 day fasting ritual in a sweat lodge set up inside a Best Buy, I will now tempt the Gods of Hubris and make my guesses for the year in mobile.

Targeting the highest common denominator

Some would claim that native is the best approach, but that looks at existing WORA tools/communities, which mostly target cost saving. In fact, even native Android/iOS tools produce rather bad results without deep platform familiarity. Native is very difficult to properly maintain in the real world and this is easily noticeable by inspecting the difficulties we have with the ports of Codename One, this problem is getting worse rather better as platforms evolve and fragment. E.g. Some devices crash when you take more than one photo in a row, some devices have complex issues with http headers, and many have issues when editing text fields in the “wrong position”.

There are workarounds for everything, but you need to do extensive testing to become aware of the problem in the first place. WORA solutions bring all the workarounds and the “ugly” code into their porting layer, allowing developers to focus on their business logic. This is similar to Spring/Java EE approaches that addressed complexities of application server fragmentation.

Featured Video

The Internet of Things That Do What You Tell Them: Cory Doctorow passionately explains how computers are already entwined in our lives, which means laws that support lock-in are much more than inconveniences.