"ios" entries

Parallax scrolling for iOS with Swift and Sprite Kit

Learn how to add this popular visual effect to your iOS project.

Up until the mid 1990s, the pinnacle of video game graphics was parallax scrolling: the use of multiple scrolling backgrounds, which created a sense of depth and perspective in the game. When you’re being a 2D game in Sprite Kit, you can create this effect by creating multiple sprites, and managing their position over time.

In this example, we’re creating a scene where there are four components, listed in order of proximity:

  • A dirt path
  • Some nearby hills
  • Some further distant hills
  • The sky

You can see the final scene below:

Read more…

Swift-like Swift code

A brief introduction to Swift optionals.

swift_swarm

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.

Read more…

Upward Mobility: Avoid This Simple App Store Bounce

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.

Here’s a nice little function that will do just that, courtesy of Apple:

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
    assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);

    NSError *error = nil;
    BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES]
                                  forKey: NSURLIsExcludedFromBackupKey error: &error];
    if(!success){
        NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
    }
    return success;
}
Back to Top

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.

Read more…

Upward Mobility: Animating the Leaves of Fall (in Australia)

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:

Read more…

Talking to Chromecast from iOS

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.

Read more…

Transcending UIAlertView on iOS 7

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.

Read more…

Upward mobility: TVs are the new mobile

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

photo: EricaJoy http://en.wikipedia.org/wiki/File:Chromecast_dongle.jpg 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.

Read more…

Four short links: 20 January 2014

Four short links: 20 January 2014

iOS Pentesting, Twitter's Infrastructure, JS Data Sync, and Chromium as C Runtime

  1. idb (Github) — a tool to simplify some common tasks for iOS pentesting and research: screenshots, logs, plists/databases/caches, app binary decryption/download, etc. (via ShmooCon)
  2. Twitter Infrastructure — an interview with Raffi Krikorian, VP of Platform Engineering. Details on SOA, deployment schedule, rollouts, and culture. (via Nelson Minar)
  3. Orbit (Github) — a standalone Javascript lib for data access and synchronization.
  4. Chromium is the New C Runtime — using Chrome’s open source core as the standard stack of networking, crash report, testing, logging, strings, encryption, concurrency, etc. libraries for C programming.

Upward Mobility: Predictions for 2014

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.

Read more…

Four short links: 5 December 2013

Four short links: 5 December 2013

R GUI, Drone Regulations, Bitcoin Stats, and Android/iOS Money Shootout

  1. DeducerAn R Graphical User Interface (GUI) for Everyone.
  2. Integration of Civil Unmanned Aircraft Systems (UAS) in the National Airspace System (NAS) Roadmap (PDF, FAA) — first pass at regulatory framework for drones. (via Anil Dash)
  3. Bitcoin Stats — $21MM traded, $15MM of electricity spent mining. Goodness. (via Steve Klabnik)
  4. iOS vs Android Numbers (Luke Wroblewski) — roundup comparing Android to iOS in recent commerce writeups. More Android handsets, but less revenue per download/impression/etc.