WatchKit Introduction: Building a Simple Guess Game

Editor’s note: Apple Watch is expected to release in the coming months. But as you know, the company already released WatchKit, the SDK that allows developers to create apps for its upcoming Apple Watch, along with Xcode 6.2 beta. So you may have already played around with it and started building Watch apps. If not, this beginner tutorial is for you. This week Julian from Julo’s development will give you an introduction to WatchKit and show you how to build a simple guess game using the SDK. You’ll learn how to create a Watch app, layout the app UI and test the app.

Enter the WatchKit tutorial.

WatchKit was first released by Apple on November 18th, 2014, along with Xcode 6.2 beta. The SDK allows developers to create and develop apps for the Apple Watch. To develop applications for the Apple Watch, you’ll need to have a paid developer account to download Xcode 6.2 beta. The demo app will be written in Swift. So I expect you have some basic knowledge of Swift programming.

watchkit-intro

Okay, let’s get started.

[Read more…]

Building a Chat App in Swift Using Multipeer Connectivity Framework

When programming in iOS, there are certain aspects of the SDK that pull the developers’ attention and interest a lot more than others, and one of them is the Multipeer Connectivity framework. As you know, the MPC framework is not new in iOS 8, instead it was first-introduced in the seventh (7th) version of it, about a year and a half ago. In the past, I’d written a couple of tutorials about it, and to tell the truth, I was surprised from the interest that people seemed to have about it. Now, some months later, I return with a new post regarding it, as I believe that there are still things that need to be explained.

You may wonder why I bring to the surface a topic a bit old, and not something new included in iOS 8. Well, I’m doing that for three reasons:

  1. Many readers have approached me through e-mail messages, asking how to perform various tasks in multipeer connectivity that were not mentioned in the previous two tutorials. By answering to all those messages, I found out that there’s a need that I hadn’t noticed earlier; People want more information about it, which is hard to find sometimes.
  2. The implementation I presented in the last couple tutorials was based in the use of a default, pre-made view controller existing in the iOS SDK for inviting other peers and establishing a connection. I found out that people was asking for manual implementation, and that’s something we are about to see here.
  3. I think that it will be quite useful and educational to see how to implement MPC in Swift.
Multipeer Connectivity Framework in Swift

During the lifetime of the multipeer connectivity framework, it has been proved that the possibilities that it came to offer gave birth to new ideas to a great number of developers. Connecting devices using such a simple way seems so attractive, and that’s why programmers want to integrate it into their applications. However, if you haven’t used the MPC framework yet, I must warn you: Sometimes it’s not as reliable as you may expect, and that’s something I’ve seen personally in my projects, and also other developers have reported to me. MPC uses both Bluetooth and WiFi to connect nearby devices, but even though it sounds too good and promising, sometimes the connection either fails or is to slow, leading to communication errors. That’s important in cases you need to transfer vital data. I would advice you to use a backup communication solution (such as a web service), so you make sure that there is an alternative and your application will continue to work even if the MPC fails. However, despite to what I just said, I still believe that MPC if a good tool for all iOS developers, so it worths it one (last) more tutorial.

[Read more…]

A Look at the WebKit Framework in iOS 8 – Part 2

In the first part of the WebKit tutorial, we covered the basics of the WebKit framework. In this tutorial, we’ll dive deeper into WebKit and look at how we can customize web pages loaded by our native app. We’ll also see how we can extract data from web pages and use it in our app.

We’ll build an app that is specifically meant to browse appcoda.com. To follow along, download the starter project. The starter project is a simple browser named Coda, much like the one we built in the first part of this tutorial. The only difference is that it doesn’t have a text field for the user to input a url to be loaded and I replaced the Back, Forward and Reload buttons text with icons.

webkit-javascript

[Read more…]

A Look at the WebKit Framework – Part 1

If you’ve ever built an application that required a webview to load web content in your native app, then you have probably experienced the frustrations that came with using UIWebView. UIWebView is quite limited and its performance lags behind that of Mobile Safari. JavaScript, which powers just about every web application, performs poorly in native mobile applications.

However, all of this has changed with the introduction of the WebKit framework in iOS 8. With the WebKit framework, comes WKWebView which replaces UIWebView in UIKit and WebView in AppKit, offering a consistent API across the two platforms.

The WebKit framework enables developers to create web enabled native apps that can utilize the power and Speed of Nitro, which is the JavaScript engine that powers Safari.

webkit-featured

WKWebView boasts of 60fps smooth scrolling, KVO, built-in gestures and native communication between app and webpage.

In the span of two articles, we’ll build two applications which will explore some of the features that WebKit (in particular, WKWebView) offers. For the first application (built in this tutorial), we’ll create a web browser that has some of the functionalities of Safari. The second article will go deeper into Webkit and show the more powerful features like injecting JavaScript into a web page to modify content and extract data.
[Read more…]

App Showcase #1: AffordIt Budget Tracker by Andrew Walker

Last year, we published a series of developer stories to share the learning experience of some first-time app developers. We got great feedback about the stories and their experience inspired others to learn iOS programming. Starting this year, we’re going to bring you more developer stories and showcase their apps on a regular basis. The purpose of these developer stories is twofold:

  • Some said iOS programming is hard to learn. It’s true. It’ll take a lot of hard work to become a competent developer. However, iOS programming is not rocket science. With the release of Swift, it’s now even more approachable to beginners. As long as you put your effort in and are committed to take action, we believe you can build an app from scratch. The developers we interviewed are mostly amateur app developers. We hope their stories would encourage aspiring developers to learn programming and build their own apps.
  • Other than helping our readers learn programming, we always think how to help you promote your apps. With over 1,000,000 apps, the App Store is now extremely competitive. You probably have released your first app on App Store but only got a few downloads. Even if you have a high quality product, it’s not easy to break into the top 100. In the developer stories, we’ll feature an app created by the app developer. In average, we have over 200,000 monthly readers. This is not a big number but we are quite sure it would help your apps gain some exposure. From time to time, we’ll also share the stories with our email subscribers and on our Facebook page. Together we can help each other succeed.
affordit-featured

Without further ado, here comes to the first app showcase – AffortIt.
[Read more…]

A Beginner’s Guide to Animated Custom Segues in iOS 8

When the fifth version of iOS (iOS 5) was released to the public, it introduced a brand new, revolutionary approach to the way the interface of an application was designed. That was the use of storyboards, and it was meant to change the existing designing philosophy from the ground up. Before iOS 5, each view controller had almost always an accompanying Interface Builder file, known as nib or xib, and the idea was simple: The interface of each view controller was supposed to be designed in the respective nib file, whereas all the nibs together were composing the full interface of the application. From one hand, that was handy because developers could only focus on the interface they were designing at the time, but on the other side, too much files were eventually had to be created, and even more, developers could not have a whole overview of the app’s interface.

Custom Segue in Storyboards

With storyboards all that became just history, as this new way has been used by almost the entire developer community. Storyboards had (and have) to offer three significant advantages compared to the old-fashioned technique:

  1. The whole interface design takes place in just one file. The total number of the files in a project is dramatically reduced, especially in big-sized ones. Using extra nib files is optional and is allowed for creating auxiliary views only.
  2. Developers have at their disposal an instant overview of the app’s interface and flow.
  3. The transitions between the view controllers (named scenes in terms of the interface design) and how they happen are now perfectly defined and clearly presented to developers.

From all the above, the transitions between scenes consist of a special chapter of the storyboards, and they’re mostly known as segues.

A segue is closely related to the navigation and handling of an application, as it actually defines the transitioning details when moving from one view controller to another. These details specify whether animation should be applied or not, what kind of animation, and of course, the preparation and performance of the actual transition. But not just that. A segue can also be used to pass data to the view controller that’s about to be shown, and that’s a common case scenario for almost all developers.

[Read more…]

Creating Simple Animations with Facebook’s Pop Framework

Editor’s note: When Facebook released its Paper app, it generated a lot of buzz in the app world. If you’ve used Paper before, the visual news feed reader, you should be amazed by its beautiful and fluid user interface. The design and attention to detail on the app is unmatched. The app refrains from using buttons and menus, but was built to be gesture-driven, to a degree that was uncommonly found in iOS apps at the time of its release. It went beyond Core Animation. The team has built its own animation engine to support all the smooth animations and coordinate animations with touch inputs. When I first tried out the app, I was wondering how some of the animations were implemented. Honestly I didn’t know how. A couple months later, the company open-sourced Pop, the animation engine behind its iOS Paper app. As a Facebook’s engineer described, Pop drives the scrolling, bouncing, and unfolding effects that bring Paper to life. Thanks to Facebook team. With the Pop framework, this means you can create similar animations that were found on Paper in your own apps.

The Pop framework was first released in late April, 2014. So far we haven’t written any tutorials about the framework. Thanks to Hossam who is kind enough to share with us an introduction of POP and show us how to create a few simple animations.

Enter the Pop tutorial.

pop-animations

In this tutorial, we will talk about Facebook POP framework to make great and easy animations in your own iOS apps. Like any other tutorials on AppCoda, I will help you understand and master Pop by examples. We will create four simple animations together to explore the framework.

Pop is an extensible animation engine for both iOS and OS X. In addition to basic animations including Linear, Ease-In, Ease-Out, Ease-In-Ease-Out animations, it supports spring (at the time of its release, spring animation was not supported in iOS), decay and custom animations:

  • Spring – dynamic animation that creates a nice bouncing effect.
  • Decay – dynamic animation that brings a movement to a smooth halt.
  • Custom – because the engine is designed to be extensible, you can create your own custom animations.

[Read more…]

Creating Interactive Local Notifications in iOS 8

Notifications are the way of an application to communicate with users, especially when it’s not running in the foreground. A notification, as its name implies, is used to *notify* a user either about an event, or just to remind something important. In fact, notifications are extremely useful in reminding applications, but they’re also quite handy in a number of other cases. For example, a notification can be shown when a user enters a predefined region (that’s new in iOS 8), when a download is complete, or when a friend has sent a message to a chat application. No matter what, the purpose of notifications is to pull the users’ attention, so they act on the message they see.

From the programming point of view, notifications consist of a quite standard aspect that can be easily implemented into an application. As there’s no much room for improvisation, developers almost always follow a predefined path to add notification features in their applications. That is to specify the details of the notification that will be delivered by the system, to handle the app launching due to a notification, and finally, starting from iOS 8, to handle any actions that have been set regarding them. The per application logic is the only thing that gets changed.

ios8-local-notification

Up to iOS 8 there were essentially two kinds of notifications:

  1. Local notifications: These are notifications specified by the developer and are triggered by the app itself. The exact time that they’ll appear is always scheduled.
  2. Remote notifications: In this case, the notifications can be split in two subcategories: (a) The push notifications, which are initiated into a web server, then go through the Apple Push Notification servers and finally they’re shown to users at the moment they arrive to the device. (b) The silent notifications, which are actually push notifications, but they’re not shown to the user straight away. Instead, they’re handled internally by the application in order to perform a task, and when everything is ready, a local notification is scheduled to inform the user.

Apart from the above, iOS 8 introduces the location notifications. These are actually local notifications, but they’re fired only when a user enters or exits a specific geographical or iBeacon region. Even though we won’t see much details, they’re easy to be implemented.

[Read more…]

Building a QR Code Reader in Swift

So, what’s QR code? I believe most of you know what a QR code is. In case you haven’t heard of it, just take a look at the image below. That’s QR code.

QR (short for Quick Response) code is a kind of 2-dimensional bar code developed by Denso. Originally designed for tracking parts in manufacturing, QR code has gained popularity in consumer space in recent years as a way to encode URL of a landing page or marketing information. Unlike the basic barcode that you’re familiar with, QR code contains information in both horizontal and vertical direction. Thus this contributes to its capability of storing larger amount of data in both numeric and letter form. Here I don’t want to go into the technical details of QR code. If you’re interested, you can check out the official website of QR code to learn more.

qrcode-featured

In recent years, the use of QR code has been on the rise. It appears in magazines, newspapers, advertisement, billboards and even name cards. As an iOS developer, you may wonder how to empower your app to read QR code. Some time earlier, Gabriel wrote a great tutorial on QR code. In this tutorial, we will build a similar QR code reader app but in Swift. After going through the tutorial, you will understand how to use the AVFoundation framework to discover and read QR code in real-time.

Let’s get started.

[Read more…]

Working with iOS 8 Handoff Part 2: Using Continuation Streams

In my last tutorial we met for first time the Handoff capability that was introduced in iOS 8.0. With it, an activity that is started in one iOS device can be continued to another from the point that was left off. Also, an activity can be continued on a Mac too, as long as the operating system is the version 10.10 (Yosemite) and a respective application exists. Obviously, it is a nice new feature that developers can take advantage of in order to create cool applications based on an entirely new philosophy.

Through the demo application of the previous post we managed to see the basics of the Handoff: How it’s integrated into an application, how a user activity is defined and how it can be continued to another device. In this tutorial we’ll extend that application and we will learn a bit more advanced techniques which can become handy in several cases. If you haven’t read the previous tutorial regarding Handoff, then I encourage you to read it first so it’s easier for you to follow here. Before you proceed make sure that you’ve perfectly understood what the prerequisites of the Handoff are, and what a user activity is, as it consists of the base of the Handoff and everything else regarding it.

handoff-stream-featured

A user activity object contains various useful properties, such as the user activity type which uniquely identifies an activity, and a user info dictionary, which contains the data that should be handed off. The most important data is transferred with this dictionary from device to device. However it’s not possible to transfer a lot of data to another device using this dictionary, and to be precise, Apple recommends to send data that it’s less than 3KB in size. In most cases this limit is more than enough, but a question arises here: How is it possible to send more data if needed so? The answer lies to the use of streams, which in the case of Handoff are called continuation streams, and this is exactly the topic of this tutorial.
[Read more…]