Last week we looked at how to send a simple local notification. Using the basic code provided by Apple allows you to schedule notifications to fire almost immediately as well as at a specified date and time in the future. Today, we’ll expand on this by looking at the associated delegate protocol; UNUserNotificationCenterDelegate; which allows us to detect which notification was swiped, and also detect when a notification is triggered when the app is in the foreground. To begin, download the project from here which we created in the last tutorial. [Read more…]
The UserNotifications framework was introduced with iOS 10 and has been designed to work with iOS, tvOS, and watchOS, and replaces UILocalNotification from the UIKit framework. UILocalNotification and other variants were deprecated in iOS 10.
If you want to send a notification to the lock screen of an iPhone, using the UserNotifications framework is now the way to go.
In this tutorial we’ll look at how to get a basic notification on to the lock screen. In the next tutorial, we’ll look at all the other parts that we do not cover here such as being able to put a notification on screen based on location; without using the CoreLocation framework, and we’ll also look at how to handle specific notifications so that we know which one was tapped or swiped. [Read more…]
When needing to put an alert on the view of your app the previous way to handle this was with a UIAlertView or UIActionSheet. Both of these were deprecated in iOS 8 which means if you are targeting newer versions of iOS, which you should be in many cases, you now need to use UIAlertController. If you want to see how alerts worked in iOS 8 or below, you can find an example in the Location Authorization tutorial we made a few years ago.
UIAlertController became available in the iOS 8.0 SDK. Rather than go through the differences between this class and the previously used classes we’ll just look at what can be done with the UIAlertController. [Read more…]
In the final part of this tutorial series we will make some slight adjustments to the graph, and then provide the ability to record your weight in HealthKit.
You can either jump back to the beginning where we created a line graph with Paintcode, start on step 2, or begin here by downloading the project as we left it at the end of the last tutorial. [Read more…]
When iOS 10.3 was launched it provided developers with the ability to let users change the icon in the app. In this fairly short tutorial I’ll show you how it’s done.
To begin, create a new project in Xcode. An iOS/Single View is a good place to start. Make sure you select Swift as the language. The same function can also be created with Objective-C, but this tutorial focuses on the Swift way.
We now need add some keys to Info.plist for the app. In particular, add the following: [Read more…]
In the last tutorial here I showed you how to create a line graph with PaintCode. In this tutorial we’ll use that line graph to plot some data. To do this we’ll get body mass (weight) data from HealthKit and plot it on the graph. By the end of this tutorial, you’ll see that although it was great to fetch the data from HealthKit and plot it on a graph, the app isn’t really that useful. In part 3, we will add more features that allow you to write data to HealthKit.
You can begin by downloading the basic tutorial where we left off last time found here.
Allowing the Points and Colours to Be Changed
As the current tutorial stands you can only display a static graph which is really of no use. Lets begin adding in the modifications that allow us to adjust the points and colours as needed.
To allow changes to be made we need to make a few modifications to the LineView class. We need to create some public variables. Open up LineView.swift and add the following just below the class definition:
//// Set the UIColors here. Defaults are .red and .gray
public var lineColour = UIColor .red
public var pointColour = UIColor .red
public var horizontalLineColour = UIColor .gray
//// The value of the top line on the graph (defaulted to 10)
public var height : CGFloat = 10.0
//// point0 is on the far left of the graph.
public var point0 : CGFloat = 8.0
public var point1 : CGFloat = 1.0
public var point2 : CGFloat = 2.0
public var point3 : CGFloat = 3.0
public var point4 : CGFloat = 4.0
public var point5 : CGFloat = 5.0
public var point6 : CGFloat = 6.0
//// Linewidth is defaulted to 2.0
public var lineWidth : CGFloat = 2.0
I have been a user of PaintCode since June 2012 when I downloaded version 1.1.1. PixelCut recently launched a new version, version 3, that brings Swift 3 compatibility to the mix amongst a few other features. The current version is priced at £99 which seems reasonable for the amount of time saved when creating resolution independent images for your app. Lets take a look and see what you can do with PaintCode.
The idea behind PaintCode is that you draw shapes in vector form, and then provide optional adjustments by using a simple expression language to add movement or changes to those shapes. Throw in some variables for colours, size, position etc… and then import that in to your app by way of a StyleKit and you have a real simple way of creating clean looking icons, charts, and other items to be used in your app. When the StyleKit is added to your Xcode project you can make calls to the class and use UIDraw to put your drawings on screen. The benefit is that you get resolution independent images that can look crystal clear at any size. This prevents the need to export @1x, @2x, or @3x and then regenerate if an @4x appears. Likewise, cutting down on the assets and putting them in code can be a great benefit for controlling the size of the app.
This tutorial demonstrates how you can make a line graph with PaintCode for your iOS app. This tutorial will form part of another tutorial which will demonstrate in more detail how to make the line graph usable within an app. [Read more…]
If you need to show a map to your users in iOS, one way to accomplish this is to use the MKMapView class. Mix this with the MKMapViewDelegate and you have the ability to detect movement on the map, detect the state of the map such as failure loading it as well as several other items you can monitor.
In this tutorial we’ll add a map to the view, allow the current location of the phone to be zoomed to, and allow the user to switch between the different map types which are available meaning Standard, Satellite, and Hybrid. We will also learn how to implement a delegate method and have the map move each time the user moves.
The first step is to create a Single View Application by opening Xcode and creating the new project. You can follow this tutorial if you are unsure how to create a new project. Make sure you select the language as Swift. You can uncheck unit tests, core data, and other optional extras.
Navigate to Main.storyboard and drag out a UIToolBar and seat it at the bottom of the view. Click the UIBarButtonItem (named Item) and rename the text attribute to “Current Location”. Drag out a Segment control and put that on the toolbar also. You might choose to use a flexible spacer between the button on the left and the segment to force them to the left and right edges of the toolbar. [Read more…]
When iOS 7 was announced in 2013, one of the items on the list of new API was iBeacon. The iBeacon API became part of the CoreLocation Framework by adding to the CLLocationManager class something called “Beacon Ranging”. Just like region monitoring based on location, known as GeoFencing, Apple also uses an iBeacon (or iBeacons for multiple beacons) as a region, and thus, when you come in to range of an iBeacon your iPhone can detect this and respond accordingly.
If you understand what an iBeacon is and what to do with them, you might want to jump the initial part of this post as the tutorial is further down the page. Click here to do so.
This tutorial is based on the previous iBeacon tutorial for Objective-C that I wrote in 2013. This new tutorial is based on the newer Swift programming language (version 3 at the time of writing).
What is an iBeacon?
An iBeacon is a bluetooth transmitter that emits a signal at a number of times per second (often 100ms or 10 times per second). It uses BLE (Bluetooth Low Energy) which means that a small battery, such as a coin cell, can power a device for a month or more. Using larger batteries the charge can last a year or longer.
The iBeacon is represented in iOS as a CLBeacon which has 3 properties to identify the iBeacon and another 3 to get information about the beacon. These properties are:
ProximityUUID is a unique identifier that you randomly generate for your business. An example of this could be a supermarket deploying 1000’s of beacons, but each of these would use the same UUID. This UUID does not need to be registered with Apple; you just randomly generate it when you create your app and then program each of your beacons with it. I will explain a little more about proximityUUID and how it relates to “region monitoring” later on in the tutorial. [Read more…]
Touch ID will allow you to add a layer of privacy to your app that was previously unavailable.
By requiring the user to authenticate who they are with their fingerprint you can limit access to certain data, or the entire app.
Well make a simple demo that will present an initial view and after the user has “authenticated”, we will move to another view.
Start with a new project, single view application, Swift language, Universal target.
With the project open and the storyboard displayed, click on the view controller and from the EDITOR menu select EMBED IN and choose NAVIGATION CONTROLLER.