Shrikar Archak

It does not matter how slow you go so long as you do not stop. ~Confucius

AVFoundation : Implementing Barcode Scanning in iOS8 With Swift

In iOS 7 apple introduced support for reading MachineReadable Code(Barcodes). As of today it supports these machine formats for reading. Frameworks also provide core images filters to generate these barcodes. In this post we will implement the same for iOS 8 and Swift.

  • UPCE
  • Code39
  • Code39Mod43
  • EAN13
  • EAN8
  • Code93
  • Code128
  • PDF417
  • QR
  • Aztec
  • Interleaved2of5
  • ITF14
  • DataMatrix

This is how the final example will work.

To implement barcode scanning in our app we need to have some idea about how AVFoundation works.

AVCaptureSession

AVCaptureSession is one of the key object that will help in managing the data flow from the capture stage through our input devices like camera/mic to output like a movie file. We can also provide custom presets which will control the quality/bitrate of the output.

AVCaptureDevice

An AVCaptureDevice object represents a physical capture device and the properties associated with that device. You use a capture device to configure the properties of the underlying hardware. A capture device also provides input data (such as audio or video) to an AVCaptureSession object. We also have the flexibility to set the properties on the input device like (focus, exposure etc) but the should be done while having a lock on that particular device object

AVCaptureInputDevice

AVCaptureInputDevice is useful for capturing the data from the input device.

AVCaptureVideoPreviewLayer

AVCaptureVideoPreviewLayer is special CGlayer which will help us display the data as captured from our input device

Here is the flow on how the start capturing input from the device.

UITableView and UITableViewCell Customization in Swift

Building Airbnb Discover Page

images

Our version

images

We will be using the UITableView and custom UITableViewCell to implement this page. Lets get started.

  • Create a single view application
  • Delete the existing view controller on the main storyboard
  • Drag a table view controller on to the main storyboard and make it the initial view controller
  • Select the UITableViewCell and change the height of the cell to 300

images

  • Drag imageview on the UITableViewCell . Select the pin icon and set the make sure the Trailing,Leading, Top and Bottom space to 0. Also unclick the constraints to margin.

images

  • Drag Label on the UITableViewCell.

images

  • Create a model for the list of places
  • Create a new class subclassing UITableViewController and call it PlacesTableViewController
  • Create a new class subclassing UITableViewCell and call it PlacesTableViewCell
  • Select the UITableViewController and assign the class PlacesTableViewController in identity inspector
  • Select the Table view cell and assign the class PlacesTableViewCell in identity inspector
  • Create IBOutlet from imageview and label to the PlacesTableViewCell.
  • Select the tableviewcontroller > Go to Editor > Embed in Navigation Controller
  • Add the Discover title on the navigation bar. Also add two bar button items on the navigation bar for search and bookmark.

iOS Swift Tutorial: UIPageViewController as User Onboarding Tool

UIPageViewController is another system provided view controller which can be used in a set of different usecases.

A page view controller lets the user navigate between pages of content, where each page is managed by its own view controller object. Navigation can be controlled programmatically by your app or directly by the user using gestures. When navigating from page to page, the page view controller uses the transition that you specify to animate the change.

The data source for a page view controller is responsible for providing the content view controllers on demand and must conform to the UIPageViewControllerDataSource protocol. The delegate object—an object that conforms to the UIPageViewControllerDelegate protocol—provides some appearance-related information and receives notifications about gesture-initiated transitions.

To understand the benefits of UIPageViewController lets go ahead and take a look at how mobile apps are onboarding users these days User Onboarding - Mobile Patterns or User Onboarding - Pttrns

Now that we know the use cases lets go ahead and implement them in our own app.

  • Create a single view application
  • On the main storyboard drag a PageViewController and a UIViewController as shown below

images

  • Then drag a UIImageView and place it on the UIViewController followed by a label on top of it.
  • At this point create a new file which is a subclass of UIViewController and give it a name PageContentViewController
  • Select the PageViewController and assign it a storyboard id PageViewController also select the attributes inspector and change the scroll direction to horizontal and the transition style to Scroll. images
    images
  • Similarly select the UIViewController you added and change the Storyboard id to PageContentViewController and also the class to PageContentViewController
    images

At this point we have setup the layout for the app.

Sensoro iBeacon Discovery in iOS 8 and Swift

I have been hearing a lot about iBeacon and wanted to play around with the technology to figure out its uses in mobile applications. There are a lot of use cases and here are a few of them

  • ibeacon for ecommerce applications
  • ibeacon for inventory management
  • ibeacon for home automation
  • ibeacon for retail
  • ibeacon for event management

There are a lot of verticals where usage of ibeacons can be effective. I have been doing some reasearch and I found Sensoro’s iBeacon to be a pretty good fit for the price, easy of use and battery life. I also bought a set of 3 ibeacons recently from them.

Here are some of the technical specs.

Tech Specs
1
2
3
4
5
6
7
8
9
10
11
Protocol: Bluetooth® 4.0 with iBeacon certification
System compatibility: iOS 7.0 or above;Android 4.3 or above
Chip: Nordic NFR51822
Sensors: Accelerometer,Light sensor,Temperature sensor
LED: 3 LED
Radius power: -30 dBm to +4 dBm; applicable for signal coverage optimization
Transmission range: 3 m ~ 80 m
Broadcasting interval: 100 ms ~ 1285 ms
Power consumption: 7.58 * 10-6 mAh per broadcast ( -8 dBm transmitting power )
Sleep mode power consumption: 30 μW
Supply voltage: 3.0 V

Sensoro’s additional features

  • Sensors: There are accelerometer/lightness/temperature sensors embedded.
  • Broadcast Sensor data: The sensor data is broadcast together with UUID/Major/Minor. The Smart Phone APP could get the sensor data/Beacon battery status when it gets UUID/Major/Minor when it is running at background with Sensoro SDK. The Sensoro SDK is at http://www.sensoro.com/docs/. It will be very useful for IOT scenario.

They are also coming up with a newer version called Sensoro Tag which are very good for larger deployment because of the price which costs 6.99$ per tag.

ibeacon 101

iBeacon is a new technology that extends Location Services in iOS. Your iOS device can alert apps when you approach or leave a location with an iBeacon. In addition to monitoring location, an app can estimate your proximity to an iBeacon (for example, a display or checkout counter in a retail store). Instead of using latitude and longitude to define the location, iBeacon uses a Bluetooth low energy signal, which iOS devices detect. To learn more about Bluetooth technology, see the official Bluetooth website.

To use iBeacon, you need iOS 7 or later, Bluetooth turned on, and a compatible iOS device:

  • iPhone 4s or later
  • iPad (3rd generation) or later
  • iPad mini or later
  • iPod touch (5th generation) or later

An iBeacon is identified by 3 values: proximityUUID, Major and Minor. The proximityUUID is vendor specific. A Major and Minor number which are 16bit values.

How can we use Major and Minor number? Lets assume that you are building an iphone application and is available worldwide. One use case of using the Major number would be to identify the store location and minor number to be used for differentiating the beacons within a store

Every beacon also have a measure called the rssi which indicates the signal strength as witness by your device. The recorded RSSI values range from -50 to -99 on the iPhone.Lower RSSI values correspond to a higher predicted distance between the beacon and the device.

Secret Ingredient: From Zero to 2 Apps in iOS App Store.

My journey to being an iOS developer started when Apple released their new version of iphones along with a Shiny new language called Swift.

I started reading up on how to get started with iOS development during WWDC 2014 and since then I have been following a lot of blogs , tutorials, courses etc. There was one problem though, I was trying to learn many things at once which obviously didn’t work and I kept wandering from one blog to another or from one course to another.

There are lots of really awesome blogs and I have put a list of all the resources here Getting Started with Mobile Application Development. Since the content is scattered, it would take a lot of time to find and digest the relevant content. I will give an example. Lets say you wanted to learn about UITableViews or UICollectionViews or Animation etc. Not all the useful information is available on a single blog. Most of the blogs tends to cover the same topics along with one or two blogs providing more detail about the same. I am not saying that it is a bad thing but for a newbie it can be quite frustating. I kept bookmarking a lot of link and at some point it became a nightmare to manage and find necessary links from my bookmarks.

From June till September first week I learnt a few topics but didn’t progress much. At this point I categorized all the links which I had bookmarked into individual categories like Swift, UITableViews, UICollectionViews, Core Data, CloudKit etc and started consuming the content along with building an app which uses those features and blogging about my experience.

Now comes the Secret Ingredient

Using UITableView and FooterView to Implement Commenting System: Building Yik Yak Clone Part 3

This is the part 3 of Building the Yik Yak Clone tutorial series. In this part of the tutorial we will be implementing commenting system on post/yak messages. If you haven’t gone through the Building Yik Yak Clone Part 1 and Building Yik Yak Clone Part 2 I will suggest you to go through them first before continuing.

Xcode 6 and Interface builder setup

  • Drag a UIViewController on to the main storyboard
  • Embed the UIViewController in Navigation Controller.
  • Drag a two UILabel on the UIViewController.
  • Drag a mapview on the UIViewController.
  • Drag a table view below the map and a UITableViewCell in the table view.
  • Drag from UITableViewCell of the previous yak listing controller to this images

Create custom DetailViewController and CommentTableViewCell

Create new view controller DetailViewController of type UIViewController and a custom tableview cell CommentTableView of type UITableViewCell.

Setup the IBoutlet for yakText, timeLabel , mapView and tableView in DetailViewController. And IBOutlet commentText in CommentTableViewCell.

Setup the constraints for all the elements as below.

images
images

Parse Backed UITableView in iOS 8 : Build Yik Yak Clone Part 2

This is the Part 2 of the Building Yik Yak Clone. If you haven’t looked at Part1 I suggest you to look at Building Yik Yak Clone Part 1 before continuing further.

In the part one we left at the point where the data in the UITableView was static and hardcoded in the app. In the real world application we normally tend to fetch the data from a REST based server or Mobile backend as a service like Parse. In this tutorial series we will use Parse for storing the data. Find more on how to Integrate Parse in your app

Lets get started.

  • Add a bar button item on to the top right of the table view and change the identifier to Compose
  • Drag a view controller next to the existing table view controller.
  • CTRL+Drag from the compose button on to the view controller you just added and select present modally
  • Now embed the view controller you just selected in a navigation controller using Editor -> Embed in -> navigation controller
  • Drag a text view on to the new view controller you just added and have the settings/attributes as mentioned below. images
  • In this particular example I am not adding autolayout constraints and getting scrollviews to work with Autolayouts is a bit tricky.. I will have a seperate post just for that. For now set these values(or appropriate values) in the size inspector. images
    images

Integrate Parse With Swift in iOS8 Using CocoaPods

This is a prerequisite for part 2 if you are following the Building Yik Yak Clone

Integrating Mobile backend Service(Parse) in your app

We will be using CocoaPods instead of the linking the frameworks directly in our apps.

What is CocoaPod

CocoaPods manages library dependencies for your Xcode projects.

The dependencies for your projects are specified in a single text file called a Podfile. CocoaPods will resolve dependencies between libraries, fetch the resulting source code, then link it together in an Xcode workspace to build your project. For more info CocoaPods

Installing CocoaPod

sudo gem install cocoapods

Create a Podfile in you root directory of your project.

bash
1
2
3
4
Shrikars-MacBook-Pro:YikYak shrikar$ ls
Podfile           Podfile.lock     Pods            YikYak          YikYak.xcodeproj YikYak.xcworkspace   YikYakTests     home.gpx
Shrikars-MacBook-Pro:YikYak shrikar$ cat Podfile
pod 'Parse-iOS-SDK', '~> 1.3'

Install dependencies. pod install

At this point a new YikYak.xcworkspace will be created in the root folder of your project. We need to start using this project instead of using YikYak.xcodeproj directly. But before we do that lets close our current project in the xcode as show below

images

Now open the YikYak.xcworkspace in your workspace and it should look something like this.

images

Parse Integration

iOS App Design Using Xcode 6 and Interface Builder - Yik Yak Clone Part 1

iOS App Design using Xcode 6 and Interface Builder - Yik Yak clone Part 1

This is the part 1 of the multipart series of Building an app every month in 2015. In this month we will build a Yik Yak iOS app clone .

What you will learn as a iOS developer

  • Designing layouts for an iOS application
  • Getting users location using CoreLocation
  • Saving data to a cloud backend Parse.
  • Fetching data around your location
  • UITableViews and Customization.

This is what you will be building

images

First and the foremost thing is go ahead install the app Yik Yak and play around with it to get a feel of how the application works.

Yik Yak helps you to find what people are talking about around you. Around you is the key to the app being so viral these days. I personally feel that the apps which provides context like location are really interesting.

With that said lets go ahead and create a single view application. Since we are going to build the app from scratch, delete the single view controller which you see in on the Main.storyboard.

This tutorial includes detailed steps. If you prefer to watch a video instead click here Yik Yak Clone

From the object library drag a Tableview controller, click on the is intial view controller checkbox , then go to editor embed in Navigation controller.

images

With the table view cell selected go to the size inspector and change the height to 100.

images

Swift Tutorial : CoreLocation and Region Monitoring in iOS 8

Location Authorization

Request for authorization for all location functionality. The authorization message can be customized. In iOS 8 there are two Authorization types

  • When in use
  • Always Authorization

Prerequisites for getting CoreLocation to work in iOS 8

Info.plist keys

Two news keys are added to the info.plist and one of them is mandatory if you want to use location in your app.

  • NSLocationAlwaysUsageDescription
  • NSLocationWhenInUseUsageDescription

The value of the keys is the message which you want to display when requesting the authorization.

images

Add Require Frameworks

Add CoreLocation and MapKit(If you want to display a map) to the Build Phases

images

Enable Background mode

If you want any features for signification location changes or region monitoring make sure you enable the background mode to location in the capabilities tab.

images

Creating a GPX file.

Xcode allows you to add custom gpx file to simulate location. To create a gpx file go to http://gpx-poi.com/ provide the longitude and latitude and any other features, then select for mac and download the xml file. And then add it to Xcode as described below.

You can edit the scheme to make this newly added gpx location as your default location.

images

Lets look at flow for getting any location information